0
tell me the output of the following program with explanation...Thnx
#include<iostream.h> #include<conio.h> void main() { float c; int a=10,b=3; c=(float)(a/b) coutăc; getch(); }
4 Answers
+ 1
OUTPUT: 3
EXPLANATION: You are first dividing both integers and then typecasting the result to float.
integer/integer gives integer as result.
SOLUTION:
c= (float) ( (float)a/ (float)b );
or c= (float)a/ (float)b;
0
The output is 3 because c is 3.0f at the end.
That's because you cast (a/b) to float, but a and b are ints so the result of a/b has to be an int, wich then you cast it to a float. So, a/b = 3 and float(a/b) = 3.0f
0
3
- 1
3.33