There is a given C code:

Given two non-negative numbers a and b. Find their geometric mean, that is, the square root of their product:

#include <math.h> #include <stdio.h> main() { double a, b; double p, kkp; printf("Dannaya programma vychislyaet kvadratnyi koren' proizvedeniya dvuh " "chisel.\n"); printf("Vvedite 'a':"); scanf("%f.\n", &a); printf("Vvedite 'b':"); scanf("%f.\n", &b); p = a * b; kkp = sqrt(p); printf("Kvadratyi koren' proizvedeniya dvuh chisel = %.2f\n", kkp); return; } 

It compiles successfully, but when executed, it always returns a null value. I understand that for sure the error is trivial, but I cannot find it on my own.

  • 2
    Better code with text and not a screen this time, and 2 - which compiler? Can I read double in% f? - pavel
  • four
    Didn't you say the phrase "DO NOT USE THIS TAG" under [study-assignment]? - D-side
  • @pavel, in a text form, the code turned into a mess, so I threw the picture. MiniGW compiler using GCC. - exe-cute-er
  • @ exe-cute-er cast text, we will correct the display. - pavel
  • 2
    and I advise everyone to read double through% lf ... - pavel

1 answer 1

Double is read using the %lf prefix.

 #include <math.h> #include <stdio.h> int main() { double a, b; double p, kkp; printf("Dannaya programma vychislyaet kvadratnyi koren' proizvedeniya dvuh " "chisel.\n"); printf("Vvedite 'a':"); scanf("%lf.\n", &a); printf("Vvedite 'b':"); scanf("%lf.\n", &b); p = a * b; kkp = sqrt(p); printf("Kvadratyi koren' proizvedeniya dvuh chisel = %.2lf\n", kkp); return 0; } 
  • And for output too% lf should be used! - Pavel Mayorov