1.

Write a program that asks the user to enter two integers, obtains the two numbers from the user, and outputs the large number followed by the words “is larger by – units than smaller number” to the system console (e.g., if the larger number is 9 and smaller is 6, message should be “9 is larger by 3 units than smaller number”). If the numbers are equal print the message “These numbers are equal”. 

Answer»

#include<iostream.h>

#include<conio.h>

void main()

{

int a,b,dif;

clrscr(); 

cout<<"Enter a:";

cin>>a;

cout<<end1<<"Enter b: ";

cin>>b;

if(a>b)

{

dif = a-b;

cout<<a<<" is larger by " <<diff<<"units than smaller number"<<end1;

}

else if(b>a)

{

dif = b-a;

cout<<b<<"is larger by"<<dif<<"units than smaller number"<<end1;

}

else

cout<<"These numbers are equal"<<end1;

getch();



Discussion

No Comment Found

Related InterviewSolutions