Friday, April 26, 2013

Array: Sum of all values from an array in C

Write a program in c which will read and sum of all values an array 



#include<stdio.h>
#include<conio.h>
main()
{
    int a[100],i,n,sum=0;
    printf("\n\tIT'S A PROGRAM TO FRINT & SUM OF ALL VALUES AN ARRAY\n");
    printf("\n\tEnter the array size: ");
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
         printf("\nEnter the %d value: ",i);
        scanf("%d",&a[i]);
        sum+=a[i];
    }
    printf("\n\tThe sum is %d:\n",sum);
}

1 comment: