26.0k views
1 vote
Write an algorithm that receives 500 numbers from the user and prints out the maximum of the numbers.

User Noobgineer
by
8.3k points

1 Answer

3 votes

Answer:

Algorithm:

1.Create a variable "maxx" and initialize it with INT_MIN.

2.Create an array of size 500.

3.for i=0 to 499.

3.1 Read value from user and store in array.

3.2 if input >maxx.

3.3 maxx=input.

4.maxx will have the largest of all 500 numbers.

5.end program.

Implementation In C++:

#include <bits/stdc++.h>

using namespace std;

// main function

int main()

{

// variable

int maxx=INT_MIN;

// array of size 500

int arr[500];

cout<<"Enter 500 numbers:";

for(int i=0;i<500;i++)

{// read input number

cin>>arr[i];

// find maximum

if(arr[i]>maxx)

maxx=arr[i];

}

// print maximum

cout<<"Maximum of all:"<<maxx<<endl;

return 0;

}

User JBux
by
8.5k points

No related questions found