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 <iostream>
#include <conio.h>

using namespace std;

int main()
{
    int n;
    cout<<"Enter a number ";
    cin>>n;
    if(n>=10 && n<100)
    {
        cout<<"Its a two digit positive number";
    }
    else if(n>=100 && n<1000)
    {
        cout<<"Its a three digit positive number";
    }
    else
    {
        cout<<"Other digit number";
    }
    return 0;
}

Output

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