r/programminghelp • • 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

4 comments sorted by

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);)

0

u/[deleted] Jan 31 '21

[deleted]

5

u/noOne000Br Jan 31 '21

how can i do this?

0

u/[deleted] Jan 31 '21

[deleted]

1

u/[deleted] Feb 11 '21

This is not C#.