#include <stdio.h>
main()
{
int i,j,n;
long sum=0,temp=0;
printf("Please input a number to n:\n");
scanf("%d",&n);
if(n<1)
{
printf("The n must no less than 1!\n");
return;
}
@for(i=1;i<=n;i++)
{
temp=0;
for(j=1;j<=i;j++)
temp+=j;
sum+=temp;
}
printf("The sum of the sequence(%d) is %d\n",n,sum);
getchar();
getchar();
}
循环次数 结果
2 sum=1+1+2
3 sum=1+1+2+1+2+3
4 sum=1+1+2+1+2+3+1+2+3+4
5 sum=1+1+2+1+2+3+1+2+3+4+1+2+3+4+5
针对for循环来次解析
两次@
第一次sum=0+1
第二次sum=(1)+1+2 括号为原来存有的值相对于上次循环
依此类推1+...+1+。。。+(n-1)+1+...+n
然后这样的值有什么意义呢?
1
1 2
1 2 3
1 2 3 4
1。。。。。n
图像编程对于点的查找?