#include "stdio.h"
int main()
{
int n,sum=0,i;
printf("Please input a number:\n");
scanf("%d",&n);
for(i=1;i<=n;i++)
sum+=i;
printf("The sum is %d.\n",sum);
}
这个很简单,不需要循环
#include "stdio.h"
int main()
{
int n,sum=0;
printf("Please input a number:\n");
scanf("%d",&n);
sum = (n *(n+1))/2;
printf("The sum is %d.\n",sum);
return 0;
}
#include
void main()
{
int i,n,s=0;
scanf("%d",&n);
for (i=1;i<=n;i++)
{
s+=i;
}
printf("%d",s);
}
#iiclude
main(){
int i,n,s=0;
scanf("%d",&n);
for (i=1;i<=n;i++) s+=i;
printf("%d",s);
}
void main()
{
int n,i;
int sum = 0;
scanf("%d", &n);
for(i = 1; i < n+1; i++)
{
sum = sum + i;
}
printf("%d\n", sum);
}