Saturday, March 2, 2013

C Language Example # 30 Array Example : Sum of All Elements of Array


C Language Example # 30 Array Example : Sum of All Elements of Array.

* Program will sum all elements from array and will display output.

//Written by Latest Technology Guide    
//Title : C Language Example # 30 Array Example : Sum of All Elements of Array.


#include <stdio.h>

#include <conio.h>
void main()
{
clrscr();
int a[10]={0},i,sum=0;

printf("\n Now Enter Value for Array A : ");

for(i=0;i<10;i++)
{
printf("a[%d] = ",i);
scanf("%d",&a[i]);
}

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

printf("\n\n\t The Sum of All Number is : %d",sum);

getch();
}


Output:

* Program will sum all elements of array.
* Program will display sum.

--------------------------------------------------------------------------------
Explanation of C Programming Language Example # 30 Array Example : Sum of All Elements of Array.


* Program will create static array.
* Program will scan value from users and will store into array.
* Program will sum all elements of array.

Note: All programs are developed and tested using Turbo C++ 3.0 under Windows XP. We just want to provide guidelines to the users. If you are using any other Compiler or other operating system they you need to modify this program as per your requirements. 

1 comment: