I tried to write a simple c program that does something with derivatives, but that’s not the point of the question:
When I run the program, It asks me to input a bunch of floating point values, but it doesn’t matter what I input the scanf function will always assign “junk” values to the variables, here’s the code:
double a, b, c, d, x, h;
printf("Please enter the coefficient of X cubed: ");
scanf("%3f", &a);
printf("\nPlease enter the coefficient of X squared: ");
scanf("%3f", &b);
printf("\nPlease enter the coefficient of X: ");
scanf("%3f", &c);
printf("\nPlease enter the free coefficient: ");
scanf("%3f", &d);
printf("\nPlease enter x: ");
scanf("%3f", &x);
printf("\nPlease enter the offset: ");
scanf("%3f", &h);
printf("%.3f %.3f %.3f %.3f %.3f %.3f", a,b,c,d,x,h);
I enter the values for a, b, c, d, x and h, but the printf function shows really weird values – completely different from what I entered.
I googled it in every possible way I thought of, and I can’t seem to find the reason it happens.
Can someone try to figure out why it happens?
Use
lfconversion specifier to readdoublevalues and notfconversion specifier which is specifief to readfloatvalues.fscanfandfprintffunctions are not symmetrical in that respect.