#include
{
int i,j;
double sum,m;
sum=0;
for(j=1;j<=99;j=j+2) {
m=1;//初始化放在这里
for(i=j;i<=j+2;i++) //j+2
{
m=m*i;
}
sum=sum+m;
}
printf("%.lf\n",sum); //这里是lf
return 0;
}
#include
int main()
{
int j;
double sum = 0;
for(j=1;j<=99;j=j+2)
sum=sum+j*(j+1)*(j+2);
printf("%.lf\n",sum);
return 0;
}
算法有误——
void main(void){
int j,sum=0;
for(j=1;j<=99;j=j+2)
sum=sum+j*(j+1)*(j+2);
printf("%d\n",sum);
}
#include
int main()
{ int i,j;
double sum,m;
sum=0;
m=1;
for(j=1;j<=99;j=j+2)
{
m=1;
for(i=j;i<=j+2;i++)
{ m=m*i;
}
sum=sum+m;
}
printf("%f\n",sum);
return 0;
}
错误,i<=2*j+1,肯定不对,m没有初始化,printf("%d\n",sum,格式错误
不用double型的
#include
int main(){
int i,j;
long sum,m;
sum=0;
m=1;
for(j=1;j<=101;j=j+2)
{
for(i=j;i<=2*j+1;i++) {
m=m*i;
}
sum=sum+m;
}
printf("%d\n",sum);
system("pause");
return 0;
}