Write a C++ program to accept a number and if it is less than 50 and greater than 20 than print its square value.

Q21. Write a C++ program to accept a number and if it is less than 50 and greater than 20 than print its square value.

Solution:

#include<iostream.h> //standard input/output header file

#include<conio.h> //for clrscr()

 

int main()

{

int a;

 

clrscr(); //for clearing the screen

 

cout<<“\n Enter a number: “;

cin>>a;

 

a<50&&a>20? cout<<“\n The square of number is “<<a*a<<“.” : cout<<“\n The number is “<<a<<“.”;

 

getch(); //holds the screen until any key is pressed

return 0; //makes main() finish

}

 

 

OUTPUT:

CASE 1:

Enter a number: 45

 

The square of number is 2025.

 

CASE 2:

Enter a number: 78

 

The number is 78.

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: