Q.19 Write a program to read a positive number from user and check whether the number is within range of 1-100, 101-200, 201-300 ,301-400 or greater than 400.
==> Code goes like this :
/* Printing the range of entered number */
#include<stdio.h>
int main()
{
int num;
printf("\n Enter the number:");
scanf("%d",&num);
if(num>=1 && num<=100)
{
printf("\n Range(1-100)");
}
else if (num>100 && num<=200)
{
printf("\n Range(101-200)");
}
else if (num>200 && num<=300)
{
printf("\n Range(201-300)");
}
else if (num>300 && num<=400)
{
printf("\n Range(301-400)");
}
else
{
printf("\n Range greater than 400");
}
return 0;
}
Output:
Output1:
Output2:
I have used Dev CPP to compile this program.
If you are using Turbo C++ IDE, then use conio.h in link section after stdio.h
and use getch(); to hold the output screen, just before the end of main function.
If you have any confusion regarding the program, please, comment below.
Happy Coding !
Check the range of entered number in C
10:03 PM
C Programs
,
if statement in c
,
if...else statement in c
,
printing a range according to entered number by user
,
range printing in c
Edit
0 comments:
Post a Comment