Write a C program to rear n elements in an array and calculate the sum of all the elements of the array.

#include <stdio.h>
main()
{
    int arr[100],i,j,n,sum=0;
    printf("\nEnter the number of elements : ");
    scanf("%d",&n);
    printf("\nEnter the elements :");
    for (i = 0; i < n; i++)
    {       
        scanf("%d", &arr[i]);
    }
    printf("\nThe list is :");
    for (i = 0; i < n; i++)
        printf("%9d ", arr[i]);
    printf("\n");
    for (i = 0; i < n; i++)
        sum=sum+arr[i];
    printf("\nThe sum of the array elements=%d",sum);
}

No comments:

Post a Comment