请帮帮我,我的头已经准备好了
#include<stdio.h>
int main(void){
unsigned short sum1=0;unsigned short counter=0;
printf("Enter the number of integers you want to sum\n");scanf("%hd",&counter);
for (unsigned int i=1;i<=counter;++i)
{
printf("The i is %d and the sum is %d\n",i,sum1);
sum1 =0;// 2 iteration sum =0;
printf("The i is %d and the sum is %d\n",i,sum1);
for(unsigned int j=1;j<=i;++j)
sum1 =sum1+j;// 1 iteration sum=1;
printf("The i is %d and the sum is %d\n\n",i,sum1);
}
return 0;
}
直到现在我读的书在用于放置花括号的嵌套循环中但不是在这个例子中......问题1)为什么在第二次迭代中总和将是3而不是2(我问这个是因为总和在去之前初始化为0嵌套的)?问题 2) 为什么当我想 printf() 时 j 会出现错误?谁能解释一下这个程序是如何工作的?我的意思是第一次迭代,第二次迭代......谢谢兄弟......