Answer to Question #172415 in Algorithms for JoshColl

Question #172415

Using flowcharts, write an algorithm to read 100 numbers and then display the sum.


1
Expert's answer
2021-03-17T04:39:16-0400

Algorithm:


  1. start
  2. initiate variable sum=0, number_elements
  3. Scan the array element
  4. sum=sum+array[i]
  5. end.
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS