Dremendo Tag Line

Square of middle digit in C

scanf() - Question 7

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

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

Program

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

int main()
{
    int n,md;
    printf("Enter a three digit number\n");
    scanf("%d",&n);
    md=(n/10)%10;
    printf("Square of middle digit=%d",md*md);
    return 0;
}

Output

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