Dremendo Tag Line

Square of middle digit in C++

cin - Question 7

In this question, we will see how to input a three digit number in C++ programming using the cin statement and find the square of its middle digit. To know more about cin statement click on the cin statement lesson.

Q7) Write a program in C++ to input a three digit number and find the square of its middle digit.

Program

#include <iostream>
#include <conio.h>

using namespace std;

int main()
{
    int n,md;
    cout<<"Enter a three digit number\n";
    cin>>n;
    md=(n/10)%10;
    cout<<"Square of middle digit="<<md*md;
    return 0;
}

Output

Enter a three digit number
562
Square of middle digit=36
video-poster