writing a program

How do i write a program to print the larger of any 2#.
write a program to print the largest of any distinct 3#
Assuming that '#' is to be replaced by 'numbers'
1) you compare them using a '<' or '>' operator. You can use an if or the ternary operator.
2) use the program you made before and call it twice.
1) how do i compare them ]
2) and how do i call it twice
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
using namespace std;
int main()
{
    int nOne;
    int nTwo;
    cout << "input first number"<<endl;
    cin >> nOne;
    cout << "input second number"<<endl;
    cin >> nTwo;
    if (nOne>nTwo)
    {
        cout << nOne;
    }
    else if(nOne<nTwo)
    {
        cout << nTwo;
    }
    else
    {
        cout << "they're equal";
    }
    return 0;
}


here's the code for your first program
Last edited on
1
2
#include <iostream>
int main(){int a[2];std::cin>>a[0];std::cin>>a[1];a[0]>a[1]?std::cout<<a[0]:a[1]>a[0]?std::cout<<a[1]:std::cout<<"even";}


Here you go op.
Last edited on
For your second program, you can simply add another number then compare the three of them one by one.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>
using namespace std;
int main()
{
    int nOne;
    int nTwo;
    int nThree;
    cout << "input first number"<<endl;
    cin >> nOne;
    cout << "input second number"<<endl;
    cin >> nTwo;
    cout << "input third number"<<endl;
    cin >> nThree;
    if (nOne>nTwo>nThree)
    {
        cout << nOne;
    }
    else if(nOne<nTwo<nThree)
    {
        cout << nThree;
    }
    else if(nTwo>nThree>nOne)
    {
        cout << nThree;
    }
    else
    {
        cout << "they're equal";
    }
    return 0;
}

you're welcome op.
Topic archived. No new replies allowed.