. C program to sum n numbers using an array.

#include <stdio.h>
#include <conio.h>
     int main()
     {
        int num, sum = 0, i, array[10];

        printf("\n How many numbers you want to add?\n");
        scanf("%d", &num);

        printf("\n Enter %d integers:", num);

        for (i = 1; i <= num; i++)
        {
          scanf("%d", &array[i]);
          sum = sum + array[i];
        }

        printf("\n Sum of all elements of an array = %d\n", sum);

        return 0;
        getch();
     }

Run:


No comments:

Post a Comment

100 C Programs with Code and Output

Program 1: C Program To Read Two Numbers And Print The Sum Of Given Two Numbers. Program 2: C Program To Read Three Numbers And Prin...