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);
}
Answer Posted / 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 |
Post New Answer View All Answers
Is c a great language, or what?
What is pass by value in c?
What is substring in c?
What is the difference between text and binary modes?
"C" language developed by "Dennis Ritchie" at AT & T. his remarks are a) too general, too abstract b) could deal with only specific problems c) lost generality of BCPL and B restored d) no remarks
What is the most efficient way to store flag values?
What is pointer & why it is used?
Write a program on swapping (100, 50)
Explain which of the following operators is incorrect and why? ( >=, <=, <>, ==)
What is a good way to implement complex numbers in c?
Is c still relevant?
What are the general description for loop statement and available loop types in c?
How do c compilers work?
What was noalias and what ever happened to it?
What is a static function in c?