II-38 Programming Concepts
19.
void main()
{
float f=5/2;
clrscr();
printf("
%f",f);
}
Bug: No bug. However, to get the desired output as 2.5, either 5 or 2 should be float
or explicit type casting is required.
20.
void main()
{
float d=65535.43;
double p=65789.987654;
clrscr();
printf("%d %d",d,p);
getche();
}
Bug: No bug. However, to get the desired output format provided is wrong. %f and %lf
are needed. Answer would be
65535.429688 65789.987654
21.
void main()
{
float d=1234567.43;
double p=987654321.1234567;
clrscr();
printf("
%f %lf",d,p);
printf("
%d %d",size of(d),size of(p));
getche();
}
Bug: Space between size and of should be removed. The answer will be
1234567.375000 987654321.123457
4 8
M02_ITL-ESL4791_02_SE_C02.indd 38 12/22/2012 4:59:43 PM