读取并存储一系列整数的C程序

时间:2019-09-24 16:25:01

标签: c

我该如何编写一个程序,该程序读取并存储一系列整数,首先求N,然后将值读入数组,然后计算前N个值的总和?

1 个答案:

答案 0 :(得分:0)

void main() {
    int N,i,sum=0,temp;
    printf("Please enter value of N\n");
    scanf_s("%d", &N);
    int *arr = (int*)malloc(sizeof(int)*N);
    for (i = 0; i < N; i++) {
        printf("Please %d value of array \n",i+1);
        scanf_s("%d", &temp);
        arr[i] = temp;
        sum += temp;
    }
    printf("Sum Of N Elemetes In Array Is %d", sum);
}