The code I wrote is # include
#include
#include
Void main ()
{
Double p, j, z, t;//
P=0;
T=1;
J=2;
For (j=2; J & lt; 100; J j + j)=2 *
{
J=2 * j + j;
P=5.8 * j;
t++;
}
Z=p/t;
Printf (" % lf \ n ", z);
system("pause");
}
Results there are errors I output respectively calculated jin number was wrong but what was wrong with you can help me have a look? J is jin, t is the day, p is the total price, z is the average money every day,
CodePudding user response:
You less a stdlib. H header fileCodePudding user response:
Your number on the first day for the second day 2 jins is 2 * 2 + 2 is 6 jins but on the third day becomes a 2 * 6 + 6 is 18 jins right should be 2 * 4 + 6 is the second day 14 kg because you buy is 4 jins should buy 8 jin on the third day can not see you buy 12 jins of such written circulation conditions there have a problem and you're in a for loop and write again j=2 * j + j this result more wrong code posted below you can see# include & lt; stdio.h>
Int main ()
{
Double p=0.00, z=0.00;//
Int t=0, j=0, I=0;
For (I=2; i <=100; I *=2)
{
If (j + I & lt; 100)
{
J +=I;
P=5.8 * j;
t++;
}
}
Z=p/t;
Printf (" % lf \ n ", z);
return 0;
}
CodePudding user response: