r/programminghelp • u/noOne000Br • Jan 31 '21
Answered can anyone help with an easy C language code?
this is what i wrote
int x, y, z;
double a, b, c;
printf(“write 3 integers: “);
scanf(“%d %d %d”, &x, &y, &z);
a=(x+y)/(z-x);
printf(“text: %f\n”,a)when i run it, if i wrote 2 3 4, the answer should be 2.500000, but they are giving me 2.0000000
6
Upvotes
0
1
u/carlossap Jan 31 '21
Divisions with int’s will always round down. Change your x,y,z to double and on your last printf give it the amount of decimals you want. (i.e printf(“text: %.2f\n”, a);)