Youssef Sakuragi Youssef Sakuragi - 1 month ago 5x
C Question

Adding 2 doubles and print them

Iam new to C and I have a problem with adding and printing some doubles in 09.3f format. This is my code:

#include <stdio.h>

int main(int argc, char **argv)
double d, m, c;

scanf("%1f", &d);

scanf("%1f", &m);

c = d + m;
printf("%09.3f\n", c);


And I have typed twice
yet I can only insert 1 number, why is that?
what i get from the printf is 00000.000

Example: d = 5,125 and m = 1.256, then i want C to be: 00006.381


Here, might be Input Buffer Problems With Scanf. So, you can add a space in the scanf. like,

 scanf("%lf", &d);

 scanf(" %lf", &m);

Also, use %lf in scanf instead of %1f.