Using flowcharts, write an algorithm to read 100 numbers and then display the sum.
Algorithm:
#include<iostream>
using namespace std;
int main(){
int n,sum=0;
cout<<"Total number of elements:"<<endl;
cin>>n;
cout<<n<<endl;
int numbers[n];
cout << "Enter the array elements:" << endl;
//Store input from the user
for (int i = 0; i < n; ++i) {
cin >> numbers[i];
}
cout << "The numbers are: ";
//Print the array elements
for (int j = 0; j < n; ++j) {
cout << numbers[j] << " ";
}
for(int k=0;k<n;k++){
sum=sum+numbers[k];
}
cout<<"\n \n The required sum of the series:"<<sum<<endl;
return 0;
}
Comments
Leave a comment