Sum of 10 elements using array
#include<iostream>
#include<conio.h>
using namespace std;
int size=10;
int main()
{
int sum=0;
int array[size]; //an array of 10 same data type elements
cout<<"Enter 10 elements : ";
for(int i=0;i<10;i++)
{
cin>>array[i];
sum=sum+array[i];
}
cout<<"10 elements you enterd are: ";
for(int i=0;i<10;i++)
{
cout<<array[i]<<" ";
}
cout<<"\nSum of all elements you entered is : "<<sum;
getch();
return 0;
}
output: -
#include<conio.h>
using namespace std;
int size=10;
int main()
{
int sum=0;
int array[size]; //an array of 10 same data type elements
cout<<"Enter 10 elements : ";
for(int i=0;i<10;i++)
{
cin>>array[i];
sum=sum+array[i];
}
cout<<"10 elements you enterd are: ";
for(int i=0;i<10;i++)
{
cout<<array[i]<<" ";
}
cout<<"\nSum of all elements you entered is : "<<sum;
getch();
return 0;
}
output: -