Compare two numbers

Hello! Today I am going to show you the algorithm for comparing two numbers and printing the result inside the console, it is fairly easy so there shouldn’t be any problems.

#include <iostream>

using namespace std;
int a,b; // declaring the variables
int main()
{
    cout << "a= ";
     cin >>a; //reading the input from the console
    cout << "b= ";
     cin >>b;  //reading the input from the console 
     //comparing the two numbers
     if(a>b)
        cout<<a<<" is greater than "<<b;
     else if(a<b)
        cout<<b<<" is greater than "<<a;
     else if (a==b)
        cout<<"The introduced numbers are equal"<<'\n';
    
    return 0;
}

I hope this helped you ,you can try it yourselves inside code::blocks !If you haven’t seen the post in which I am explaining how to create a console application feel free check it out here.

Keep on coding 😉 !

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s