Answer to Question #172411 in Algorithms for JoshColl

Question #172411

algorithm to read 100 numbers then display the largest.


1
Expert's answer
2021-03-17T06:07:58-0400
#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 l = 1; l < n; ++l) {
    if (numbers[0] <  numbers[l]) {
      numbers[0] = numbers[l];
    }
  }

    cout<<"\n \n The required sum of the series:"<<numbers[0]<<endl;
    return 0;
}
Algorithm:
start
scan the array element.
Apply for loop, initiate from zero to size of array and print the values.
for(i=0 to n)
  if (arr[0]<arr[i])
    arr[0]=arr[i]
print arr[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