请教一道C语言入门题,知道的帮下忙~~~~~~~

来源:百度知道 编辑:UC知道 时间:2024/09/26 00:32:31
In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + ... + n.
Input:
The input will consist of a series of integers n, one integer per line.
Output:
For each case, output SUM(n) in one line, followed by a blank line. You may assume the result will be in the range of 32-bit signed integer.
Sample Input
1
100
Sample Output
1

5050
输入要随即的几个数。而且要换行。输完后再输出。
例如:
输入:50
100
输出:1275

5050

按你的要求的完整c程序如下,在win-tc和tc2.0下调试通过,其中开始要输入要计算的数目个数,以便程序能顺序执行下去,同时利用数学中的公式1+2+3+...+n=n(n+1)/2简化运算,省去循环,提高执行效率,我们利用计算机不就是利用它的计算高效率末?
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#define N 10
main()
{
int i,n;
int a[N];
long b[N];
printf("Input numbers(total<=%d):\n",N);
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++)
{
b[i]=(long)a[i]*(a[i]+1)/2;
printf("The output is:%ld.\n\n", b[i]);
}
}

英语很差,不太看得懂。。
#include <stdio.h>
void main()
{
int sum = 0;
for (int i = 1; i <= 100; ++i)
sum += i;
printf("%d", sum);
}

#include <stdio.h>

void main()
{
int sum=0,n;
printf("Please input n:\n");
scanf ("%d",&n);
for(i=1;i<=num;i++