Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Write a c++ program to find maximum between two numbers?

+1 vote
asked Dec 17, 2019 by Nyasha chinyerere

6 Answers

+1 vote
answered Dec 19, 2019 by anonymous
#include<iostream>
using namespace std;
int main()
{
    int a,b;
    cout<<"Enter two Numbers: ";
    cin>>a>>b;
    int max=a>b?a:b;
    cout<<"Max is: "<<max;
    return 0;
}
commented Jan 1, 2020 by anonymous
count is undeclared
0 votes
answered Dec 19, 2019 by GF (220 points)
edited Dec 19, 2019 by GF
#include <iostream>

using namespace std;

int maxFunction(double a, double b);

int main()
{
    double a, b;
    cout << "Enter first number: ";
    cin >> a;
    
    cout << "Enter second number: ";
    cin >> b;
    
    if (a != b){
        maxFunction(a,b);
    }
    else {
        cout << "You entered numbers that are equal" << endl;
    }
    
    return 0;
}

int maxFunction(double a, double b) {
    if (a > b){
        cout << "The maxium number is: " << a;
    }
    else if (b > a) {
        cout << "The maxium number is: " << b;
    }
}

----------------------------------------
Or you could use:

----------------------------------------

#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    double a, b;
    cout << "Enter first number: ";
    cin >> a;
    
    cout << "Enter second number: ";
    cin >> b;
    
    if (a != b){
        cout << "The max number is: " << max(a,b) << endl;
    }
    else {
        cout << "Both numbers are the same, the max number is: " << max(a,b) << endl;
    }
    
    
    return 0;
}
0 votes
answered Dec 20, 2019 by Armend Ostaku (140 points)
#include <iostream>
using namespace std;
int max(int a,int b){
    if(a>b)
        return a;
        return b;
    
}
int main (){
    int a,b;
    cin>>a>>b;
    cout<<"GREATEST VALUE IS : "<<max(a,b);
    return 0;
}
0 votes
answered Dec 22, 2019 by jestadi vickyath (170 points)
#include<stdio.h>
void main()
{
int x,y;

printf("enter the number");
scanf("%d",&x);
printf("enter the number ");
scanf('%d",&y);
if(x<y)
{
printf("your enterd number y Is greater");
}
else
{
printf("enter number x is greater");
}
return 0;
0 votes
answered Dec 26, 2019 by Omaru (140 points)
#include <iostream>

#include <string>

int max(int x, int y)

{
     return ( (x > y)? x : y);
}

int main(int argc , char **argv)

{

  std::cout << "Enter the first number followed by the second separated by space or return key: \n";

int x,y;

std::cin >> x >> y;

std::cout <<"Max is: << max(x,y) << std::end;

}
0 votes
answered Dec 30, 2019 by GM NARENDRA
#include<stdio.h>

int main()

{

int a,b;

printf("enter a numbers");

if(a>=b)

printf("a is maximum ");

else

printf("b is maximum");

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.
...