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



main() { unsigned int k = 987 , i = 0; char trans[10]; do { trans[i++] =(char) (k%16 > 9 ? k..

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

main() { unsigned int k = 987 , i = 0; char trans[10]; do { trans[i++] =(char) (k%16 > 9 ? k..

Answer / deepthisivan

bd

Is This Answer Correct ?    13 Yes 0 No

main() { unsigned int k = 987 , i = 0; char trans[10]; do { trans[i++] =(char) (k%16 > 9 ? k..

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

main() { unsigned int k = 987 , i = 0; char trans[10]; do { trans[i++] =(char) (k%16 > 9 ? k..

Answer / dishank

deepthisivan can u plz elaborate.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Interview Questions

What are advantages and disadvantages of recursive calling ?

12 Answers   College School Exams Tests, Evolving Systems, HP, Jyoti Ltd, Sage, Wipro,


/*what is the output for the code*/ void main() { int r; r=printf("naveen"); r=printf(); printf("%d",r); getch(); }

1 Answers   CDAC,


Is c weakly typed?

0 Answers  


Is fortran still used in 2018?

0 Answers  


How important is structure in life?

0 Answers  






write a c program thal will find all sequences of length N that produce the sum is Zero, print all possible solutions?

0 Answers   Wipro,


In CMM or CMMI certified organizations,we assess only the standard software processes of the organization. We do not assess the organizations other functional departments like HR or Admin. Then how can we certify the entire organization as CMM level company?? We have assessed only software related activities. Right. There is no relation with other departments like Accounts, HR or Admin. Then how can we claim that the whole company is a CMM certified company?

1 Answers   Melstar,


Write a program to print this triangle: * ** * **** * ****** * ******** * ********** Don't use printf statements;use two nested loops instead. you will have to use braces around the body of the outer loop if it contains multiple statements.

6 Answers   Wipro,


my project name is adulteration of chille powder.how can i explain it to the hr when he asks me about the project?

0 Answers  


What is a const pointer in c?

0 Answers  


Write a C program that defines a 2-dimentional integer array called A [50][50]. Then the elements of this array should randomly be initialized either to 1 or 0. The program should then print out all the elements in the diagonal (i.e. a[0][0], a[1][1],a[2][2], a[3][3], ……..a[49][49]). Finally, print out how many zeros and ones in the diagonal.

3 Answers   Infosys,


In this assignment you are asked to write a multithreaded program to find the duplicates in an array of 10 million integers. The integers are between -5000,000 to 5000,000 and are generated randomly. Use 10 threads, each thread works on 1000,000 integers. Compare the time needed to accomplish the task with single thread of execution program. Do not include the time to fill the array with integers in the execution time.

0 Answers  


Categories