Program to find sum of the elements in the array

 #include<stdio.h>

void main()

{

    int a[50],n,i,sum=0;


    do

    {

        printf("\nEnter no. of elements in between 1 and 50: ");

        scanf("%d",&n);

    }while(n<1 || n>50);


    printf("\nEnter the elements: ");

    for(i=0;i<n;i++)

        scanf("%d",&a[i]);


    printf("\nElements are: ");

    for(i=0;i<n;i++)

        printf("%d ",a[i]);


    for(i=0;i<n;i++)

        sum=sum+a[i];


    printf("\nSum = %d",sum);

}

Comments

Popular posts from this blog

Single Program Using All Automatic String Functions

C program for subtraction of two matrices (2D Arrays)

C program for Multiplication of Two matrices