Find greater number in c++

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

  1. Solaris

    Solaris New Member

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

    ashken New Member

    Joined:
    Oct 22, 2010
    Messages:
    8
    Likes Received:
    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. kosy

    kosy New Member

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

    jsh New Member

    Joined:
    Mar 18, 2011
    Messages:
    10
    Likes Received:
    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_zx

    Neptune_zx New Member

    Joined:
    Dec 15, 2010
    Messages:
    1
    Likes Received:
    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;
    }
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice