About Me

My photo
Raipur, Chhattisgarh, India
Hi , I am Amit Thakur. I have worked as a QA Engineer for two years and as a Java Developer for one year in NIHILENT TECHNOLOGIES PVT. LTD., Pune.Currently I am working as DEAN (Research & Development) in Bhilai Institute of Technology, Raipur.

Monday, September 2, 2013

C Program to Calculate Addition of All Elements in Array

#include<stdio.h>
#include<conio.h>

void main()
{
 int i,a[50],sum,n;
 printf("Enter no of elements :");
 scanf("%d",&n);

 /* Reading values into Array */

 printf("Enter the values :");
 for(i=0;i < n;i++)
 scanf("%d",&a[i]);

 /* computation of total */

 sum=0;
 for(i=0;i < n;i++)
 sum=sum+a[i];

 /* printing of all elements of array */

 for(i=0;i < n;i++)
 printf("a[%d]=%d",i,a[i]);

 /* printing of total */

 printf("Sum=%d",sum);
}

No comments: