首页 > 中学考试杂题 > 题目详情
关于for循环语句后的分号问题#include "Stdio.h"int main(void){long sum=0L;
题目内容:
关于for循环语句后的分号问题
#include "Stdio.h"
int main(void)
{
long sum=0L;
int count=0;
int i=0;
printf("\nplease enter the number of integers you want to sum:");
scanf("%d",&count);
for(i=count; i >=1 ;sum += i--) ;
printf("\nTotal of the first %d number is %ld;\ni=%d.\n",count,sum,i);
}
for语句后的分号不加的话,sum的结果就是从2加到count,但是加的话,sum的结果就是从1加到count.
为什么会这样!
关于for循环语句后的分号问题
#include "Stdio.h"
int main(void)
{
long sum=0L;
int count=0;
int i=0;
printf("\nplease enter the number of integers you want to sum:");
scanf("%d",&count);
for(i=count; i >=1 ;sum += i--) ;
printf("\nTotal of the first %d number is %ld;\ni=%d.\n",count,sum,i);
}
for语句后的分号不加的话,sum的结果就是从2加到count,但是加的话,sum的结果就是从1加到count.
为什么会这样!
#include "Stdio.h"
int main(void)
{
long sum=0L;
int count=0;
int i=0;
printf("\nplease enter the number of integers you want to sum:");
scanf("%d",&count);
for(i=count; i >=1 ;sum += i--) ;
printf("\nTotal of the first %d number is %ld;\ni=%d.\n",count,sum,i);
}
for语句后的分号不加的话,sum的结果就是从2加到count,但是加的话,sum的结果就是从1加到count.
为什么会这样!
本题链接: