Tuesday, 10 July 2012

Program to compare two numbers in C++


Code -


/* Program to compare two numbers in C++ */

//__ "\n" is used for new line and "\t" for a tab (spaces) ___

//__ cin is to take the input and cout is used to dispaly the output ___

#include<iostream>

//___ Header file in C++ where the standard input/output functions are defined ___

#include<conio.h>

using namespace std;

int main()
{
int first_number = 0, second_number = 0;

cout << "\n\t\t __ Program to compare two numbers in C++ ___";

cout << "\n\n  Enter the First number  - ";

cin >> first_number;

cout << "\n\n  Enter the Second number - ";

cin >> second_number;

cout << "\n\n\n\t\t       ____  ";

if (first_number > second_number) //_ If first number is greater than second _
{
cout << first_number << " is greater than " << second_number;
}
else if (second_number > first_number) //_ If second number is greater than first _
{
cout << second_number << " is greater than " << first_number;
}
else //__ if both numbers are equal __
{
cout << first_number << " is equal to " << second_number;
}

cout << " ____";

getch();

return 0;

/*____ return 0 tells the compiler that program

has executed successfully without any error ____ */

}

No comments:

Post a Comment