0

Uh,I am a biginner in programming.. my code:

int main() {
    double a,b,c,result;
    scanf("%f %f %f",&a,&b,&c);
    result = (a+b+c)/3.0;
    printf("%.3f",result);
    return 0;
}

then I type: 3 3 3 But I got: ( 3 is expected) 0.000

How can I solve this?

Marco Bonelli
  • 63,369
  • 21
  • 118
  • 128
  • 1
    Why aren't you scanning your doubles with `%lf`? You're scanning floats (`%f`) into pointers that are pointing to doubles. – Wyck May 04 '22 at 01:48
  • Do you actually even need `float` or `double` for `a`, `b`, and `c`? That is, are the inputs actually expected to be integers? If so `int` variables with `%d` would be better. – kaylum May 04 '22 at 01:49
  • 2
    王正君, Save time, enable all warnings to quickly warn about `double a,b,c,result; scanf("%f %f %f",&a,&b,&c);`. Faster than posting on SO. – chux - Reinstate Monica May 04 '22 at 01:51

0 Answers0