Dremendo Tag Line

Check 2 digit or 3 digit positive number in C

if else if - Question 1

In this question, we will see how to input a number and check if it is a 2 digit or 3 digit positive number or not in C programming using the if else if statement. To know more about if else if statement click on the if else if statement lesson.

Q1) Write a program in C to input a number and check if it is a 2 digit or 3 digit positive number or not.

Program

#include <stdio.h>
#include <conio.h>

int main()
{
    int n;
    printf("Enter a number ");
    scanf("%d",&n);
    if(n>=10 && n<100)
    {
        printf("Its a 2 digit positive number");
    }
    else if(n>=100 && n<1000)
    {
        printf("Its a 3 digit positive number");
    }
    else
    {
        printf("Other digit number");
    }
    return 0;
}

Output

Enter a number 184
Its a 3 digit positive number
video-poster