d881
輸入說明 :
每次輸入一個測資d,代表公差(d<=100)
輸出說明 :
輸出級數和(1+到50項)
先用一個陣列,把值存起來,再加總
#include<stdio.h>
int main()
{
int i;
int diff;
while(scanf("%d",&diff)!=EOF)
{
int sum=0;
int array[50]={0};
array[0]=1;
for(i=1;i<50;i++)
{
array[i]=1+(2+(i-1)*diff)*i/2;
}
for(i=0;i<50;i++)
{
sum+=array[i];
}
printf("%d\n",sum);
}
return 0;
}