# Find greater number in c++

Discussion in 'C++' started by Solaris, Oct 12, 2010.

1. ### SolarisNew Member

Joined:
Oct 12, 2010
Messages:
4
0
Trophy Points:
0
How to write a program to find greater number using conditional operator in c++ ?

2. ### ashkenNew Member

Joined:
Oct 22, 2010
Messages:
8
0
Trophy Points:
0
Code:
```//prompt the user to enter three numbers and find the greatest of them
#include <iostream>
using namespace std;

int maximum(int, int, int);

int main()
{
int a,b,c;

cout<<"Enter three numbers ";

cin>>a>>b>>c;

cout<<"The largest number is "<<maximum( a, b, c);

return 0;
}
int maximum( int x, int y, int z)
{
int max = x;

if(y > max)
max = y;

if( z > max)
max = z;

return max;
}
```

3. ### kosyNew Member

Joined:
Mar 8, 2011
Messages:
1
0
Trophy Points:
0
Location:
9ja
i need your help from glass on c++

4. ### jshNew Member

Joined:
Mar 18, 2011
Messages:
10
0
Trophy Points:
0
Code:
```
#include<iostream.h>

class max{
public:
void get(int [],int);
int sh(int [],int);
};

void max::get(int *a,int b)
{
for(int i=0;i<b;i++)  cin>> a[i];
}
//------------
void max::sh(int *a,int b)
{
int mx=a[0];
for(int i=1;i<b;i++)
if(a[i]>mx)
mx=a[i];

return mx;
}
//------------
void main()
{
max j;
int x[3];
j.get(x,3);
int m=j.sh(x,3);
cout<<" \n MAX = "<<m;
}

```

5. ### Neptune_zxNew Member

Joined:
Dec 15, 2010
Messages:
1
0
Trophy Points:
0
Code:
```#include <iostream>
using namespace std;
int main()
{
int a=12,b=57;
int greaterNum=0;
greaterNum=(a>b)?a:b;
cout<<'a='<<a<<endl
<<'b='<<b<<endl
<<"greaterNum='<<greaterNum<<endl;
return 0;
}```