#include
int main()
{
int sum = 0,t,num;
printf ("输入整数个数:\n");
scanf ("%d", &num);
for(int i=0;i
scanf ("%d", &t);
sum+=t;
}
printf ("总和是:%d\n", sum);
return 1;
}
只要总和不超过int的最大值,算的结果都能正常
#include
#define M 100 //想输入多少输入多少,自己随便改,不过不能大于2147483647个哦
int main()
{
int i, sum = 0, a[M];
printf ("输入%d个整数:\n", M);
for (i=0; i{
scanf ("%d", &a[i]);
sum += a[i];
}
printf ("这些数的和是:%d\n", sum);
return 0;
}