C Programming :: Variables & Data Types - Discussion
1 / 51
#include<stdio.h>
int main()
{
float i, j;
scanf(%f %f, &i, &j);
printf(%.2f %.3f, i, j);
return 0;
}
What will be the output for the give input 12.342 and 123.4568
#include<stdio.h>
int main()
{
float i, j;
scanf(%f %f, &i, &j);
printf(%.2f %.3f, i, j);
return 0;
}
What will be the output for the give input 12.342 and 123.4568
A12.34 123.456
B12.342 123.4568
C12 123
DCompilation Error
ENone of these
Show Explanation
I see couple of issues with question.
1. there should be compliation issue with this statement - printf(%.2f %.3f, i, j);
I have tried to complie
$ gcc -o q8 q8.c
q8.c: In function ‘main’:
q8.c:6:8: error: expected expression before ‘%’ token
scanf(%f %f,
Asked In ::
I see couple of issues with question.
1. there should be compliation issue with this statement - printf(%.2f %.3f, i, j);
I have tried to complie
$ gcc -o q8 q8.c
q8.c: In function ‘main’:
q8.c:6:8: error: expected expression before ‘%’ token
scanf(%f %f,
Read Full Answer
Report Error
Please Login First Click Here
The above code will result to compilation error, for the following reasons-
1. The 2 "%f" are not enclosed within double quotes(" "). It should be rather like- scanf("%f%f",&i,&j);
2. "%.2f" and "%.3f" inside the printf() function should be enclosed within the double quotes(" "), or simply it should have been written as- printf("%.2f %.3f",i,j);
If we correct the above code, the output will be 12.34 123.456.
%.2f simply means to print 2 digits after the decimal.
Similarly, %.3f means to print 3 digits after the decimal.
Read Full Answer
Report Error
Please Login First Click Here