Check the range of entered number in C

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 ! 
Share on Google Plus

About Nepali Xoro

Interested in Information Technology, Spreading Knowledge for Nepalease IT Students."Loves Traveling", Listen Music and Surfing web.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment