Addition of n number

Program Description

In this code the addition of given array is calculated.

Program
/***********************************
*   Addition of n number
*	
*	code.cheraus.com
*
***********************************/

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

void main()
{
  int n,i,a[20],sum=0;
  clrscr();
  //accept no of term
  printf("\nEnter number of term : ");
  scanf("%d",&n);
  
  //accept the n element
  printf("\nEnter the elements : ");
  for(i=0;i<n;i++)
   {
     printf("\nEnter the %d element : ",i+1);
	 scanf("%d",&a[i]);
   }
  
  //display the element
  printf("\nElements are : ");
  for(i=0;i<n;i++)
   printf("%d\t",a[i]);
   
  //adding element in the array
  for(i=0;i<n;i++)
    sum = sum + a[i];
	
  //display sum
  printf("\nSum of array is %d",sum);
  
  getch();
}

Output
Test Case 1:

Enter number of term :4
Enter the elements :
Enter the 1 element :1
Enter the 2 element :2
Enter the 3 element :3
Elements are :1 2 3
Sum of array is 6

Comments
comments powered by Disqus