C++Program to show the Array Elements sum.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
#include<iostream> #include<conio.h> using namespace std; int main() { int MyArray[20]; int m, loop_2, arary_size; int sum=0; cout<<"How many elements you want to enter: "; cin>>arary_size; cout<<"Enter the Elements:"; for(m=0;m<arary_size;m++) { cin>>MyArray[m]; } cout<<"Sum of Elements are: "; for(loop_2=0;loop_2<arary_size;loop_2++) { sum=sum+MyArray[loop_2]; } cout<<sum; getch(); } |
Advertisement
Advertisement