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


Please Help Members By Posting Answers For Below Questions

Is c a great language, or what?

825


What is pass by value in c?

754


What is substring in c?

841


What is the difference between text and binary modes?

849


"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

859






What is the most efficient way to store flag values?

870


What is pointer & why it is used?

786


Write a program on swapping (100, 50)

843


Explain which of the following operators is incorrect and why? ( >=, <=, <>, ==)

772


What is a good way to implement complex numbers in c?

774


Is c still relevant?

831


What are the general description for loop statement and available loop types in c?

883


How do c compilers work?

777


What was noalias and what ever happened to it?

762


What is a static function in c?

810