main()
{
int i=3;
float j=3.5;
printf("%f",i);
printf("%d",j);
}
Explain the following program in C.?
Using %f notation we print a float. Here i is a integer but printing using %f notation the it will print 3.00000
But %d notation is for integer printing so if we print a float of value 3.5 then it will print 3 only
%f -- float printing
%d -- decimal printing
Reply:Others have spotted the mistakes; there, but if this is just an exam question and they are making 'mistakes' purposely the traced output should be 0234327823784 or some weirdly long garbage number.
Reply:A simple program which prints two numbers - an integer (3) and a float (3.5)
1. The first line defines the program
2. The 3-rd and 4-th lines define the type of the numbers (3 is integer, 3.5 is float) and assigns them to variables - i and j
3. The "printf" command is used to print the numbers on the screen. "%f" means that Decimal floating point will be used to format the number, "%d" means Signed decimal integer.
So the output of the program will be the numbers 3 and 3.5
I see a mistake here. Wrong formatting is used for the numbers. Choose one of the following:
1.) printf("%d",i);
printf(%f",j);
-OR-
2.) float i=3.5;
int j=3;
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment