0
Getting the answer as 4+3+1.50000=8 instead of 8.5
# include< stdio.h> Int main() { int a =4; int b=3; float c= 1.5; int sum = a+b+c; printf ("the sum is %d+%d+%f=%d",a,b,c,sum); }
4 Answers
+ 4
Because it's int sum but it needs to be Double/ float
+ 4
You can specify the type before you assign the variable:
Also you can simply print sum as float.
#include <stdio.h>
int main()
{
int a,b;
float c,sum;
a = 4;
b = 3;
c = 1.5;
sum = a + b + c;
printf ("the sum is %f",sum);
return 0;
}
+ 2
# include<stdio.h>
int main()
{
int a =4;
int b=3;
float c= 1.5;
float sum = a+b+c;
printf ("the sum is %d+%d+%f=%f",a,b,c,sum);
}
Hope this will help u...
U have to use float sum instead of int sum for printing decimal no. And also in printf u should use %f as format specifier for float data types.
0
Thank you alot guys .. I got the problem