Monday, 18 May 2015

Write a Program in c++ which read 6 no. from keyboard and store these no into array and then calculate sum of these no. using function.

Coding:- 

 #include<iostream.h>
 int sum (int a[])
 {
int n=0;
for(int i=0;i<=5;i++)
n=n+a[i];
return (n);
 }

 int output(int a[])

 {
cout<<"the elements of array are : "<< endl ;

for(int i=0;i<=5;i++)

cout<<a[i]<<endl;

 }

 int main()

 {
 int a[6],s,i;
 cout<<"enter 6 elements : ";
 for(i=0;i<=5;i++)
 cin>>a[i];

 output(a);

 cout<<"sum of array element is : ="<<sum(a)<<endl;


 }

Output:- 
   

No comments:

Post a Comment