find the max of five numbers using C++

+1 vote
asked Feb 10 by anonymous

2 Answers

0 votes
answered Feb 13 by Sirisha (140 points)
#include<iostream>
using namespace std;
int main()

{

 int a[10]={1,5,2,3,4},i,b;

for(i=0;i<5;i++)

{

if(a[i]>a[i+1])

{

b=a[i];

a[i]=a[i+1];

a[i+1]=b;

}

}

cout<<b;

}
0 votes
answered Feb 15 by Sai Naveen Chowdary (140 points)
# include<iostream>
using namespace std;
const int values = 30;
int main ()
{
int num[values];
int max , i;
cout << "Please enter 5 numbers, so that i show you the maximum \n";
cin >> num[0] >>num[1] >>num[2] >> num[3] >>num[4];
max = num[0];
for (int i=0; i<5; i++)
if (max < num[i])
max = num[i];
cout << "The maxmum value is:" << max << endl ;
system ("pause");
return 0;
}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...