Tuesday, 11 February 2014

Write a c program to find the sum of the elements of an integer array.

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

No comments:

Post a Comment