main()
{
unsigned int k = 987 , i = 0;
char trans[10];
do {
trans[i++] =(char) (k%16 > 9 ? k%16 - 10 + 'a' : '\0' );
} while(k /= 16);
printf("%s\n", trans);
}
Answers were Sorted based on User's Feedback
Answer / ashok kumar
answer is : bd
Explanation:
trans[i++]= (char) (k%16>9?k%16-10+'a':'');// 1.(char) is typecasting it convert decimal value into character. 2. k=987%16 is greater than 9 means first condition run else second condition as of this k%16 remainder is 11 so it is greater than 9, then first condition will run.
3. 11-10+'a' = 1+'a' = 1+97 is ascii value for a = 98 is ascii value for b so it print.
4. check while condition k=k/16 = 61, so its true value again it will run do the same process but second time the k value will be 61 because it changes in while condition then after second time condition fail you will get bd is answer
while(k/=16);
printf("%s",trans);
Is This Answer Correct ? | 16 Yes | 0 No |
Answer / lakshman
first case k=987, i=0.
trans[i++]=(char)(k%16>9?k%16-10+'a':''); means
trans [0]=char(987%16(=61)>9)condition is true so k%16-10+'a' value is print. that value is equal to 61-10|+(ascii value of a, that is equal to 97) so finally we get 98 and that is equal to b,
second case k=61, i=1 this will gives d
third case k=3, i=2 this gives null character.
the final answer is bd
Is This Answer Correct ? | 1 Yes | 0 No |
Write a simple program to find the size of different basic data types in C.
who will call your main function in c under linux?
get any number as input except 1 and the output will be 1.without using operators,expressions,array,structure.don't print 1 in printf statement
What are unions in c?
Explain continue keyword in c
How can I call a function with an argument list built up at run time?
what are the stoge class in C and tel the scope and life time of it?
How can I call system when parameters (filenames, etc.) Of the executed command arent known until run time?
what is the self-referential structure?
How many types of functions are there in c?
How to write a multi-statement macro?
how to convert an char array to decimal array