C Program To Accept A Number And If It Is Less Than 10 Then Print Its Square Value.

Q20. Write a C program to accept a number and if it is less than 10 then print its square value.

Solution:

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

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

 

int main()

{

int a;

 

clrscr(); //for clearing the screen

 

printf(“\n Enter a number: “);

scanf(“%d”,&a);

 

a<10?printf(“\n The square of number is %d.”,a*a) : printf(“\n The number is %d.”,a);

 

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

return 0; //makes main() finish

}

OUTPUT:

CASE 1:

Enter a number: 9

 

The square of number is 81.

 

CASE 2:

Enter a number: 11

 

The number is 11.

Leave a Reply

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