algorithm to read 100 numbers then display the largest.
#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]
Comments
Leave a comment