How to divide 2 int in c?

后端 未结 5 2082
清酒与你
清酒与你 2020-12-10 18:29

wanna divide 2 numbers and get the result like this:

5 / 2 = 2.50

But it only outputs 2.

I don\'t now what i\'m doing wrong.

Here my code:

5条回答
  •  萌比男神i
    2020-12-10 18:40

    To avoid the typecast in float you can directly use scanf with %f flag.

    float a;
    float b;
    float c;
    printf("First number\n");
    scanf("%f", &a);
    printf("Second number\n");
    scanf("%f", &b);
    c = a / b;
    printf("%f", c);
    

提交回复
热议问题