Sunday, July 12, 2009

Can anyone please help me with this C program??

#include%26lt;stdio.h%26gt;


void main()


{


int a=012;


int b=034;


int c=056;


printf("a= %d\n",a);


printf("b=%d\n",b);


printf("c=%d\n",c);


}


if u tell me the answers r


a=12


b=34


c=56


then yr answer is wrong...when u run this program the answer is


a=10


b=28


c=46


can anyone tell me how we got these values.please its urgent

Can anyone please help me with this C program??
The reason you got these results is because in C, when you precede an integer literal with 0 (the way you did), it means that you're using octal base.





12 octal = 1*8 + 2 = 10 decimal


34 octal = 3*8 + 4 = 28 decimal


56 octal = 5*8 + 6 = 46 decimal
Reply:#include%26lt;stdio.h%26gt;


{


main();


clrscr();


printf("me\n");





getch();





}
Reply:This is becaouse when you precede a number with 0 it takes as an octal number...


Hexadecimal numbers can be represented like this 0x73 etc... (x is the alphabet 'x')





As the system took it as octal number it showed the following answers:





12 in octal is 1 * 8^1 + 2* 8^0 = 10


and similarly for the rest...





so be carefull ! ! !
Reply:12 octal = 1*8 + 2 = 10 decimal


34 octal = 3*8 + 4 = 28 decimal


56 octal = 5*8 + 6 = 46 decimal


No comments:

Post a Comment