In this tutorial you will learn about the C Program to find Square of a Number and its application with practical example.
C Program to find Square of a Number
In this tutorial, we will learn to create a C program that will find the square of a Number in C programming.
Prerequisites
Before starting with this tutorial, we assume that you are the best aware of the following C programming topics:
- Operators in C Programming.
- Basic Input and Output function in C Programming.
- Basic C programming.
- Arithmetic operations in C Programming.
What is a square of a number?
The Square of any number means a number multiplied by itself 2 times. This can also be called ‘a number squared’. The symbol for square is 2 {the power of any number is 2 for square}.
Algorithm:-
1 2 3 4 5 6 7 8 9 |
1. Declaring the variables for the program. 2. Taking the input number from the user to find the square. 3. Calculating the square of that number. 4. Printing the result square of that number to the user. 5. End the program. |
Program to Calculate the Square of a Number
In this program, we will take a number in input from the user. Then we will multiply that number by itself 2 times. After that, we will print the resultant answer to the user as an output.
With the help of this program, we can Square a number.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
/* C program to find a Square of a number */ #include<stdio.h> int main() { //declaring the required variable for the program. int no, sq ; //taking the input number from the user. printf(" \n Please Enter any integer Value : "); scanf("%d", &no); //calculating the Square of a number. sq = no * no; //Printing the output Square to the user. printf("\n Square of a given number %d is = %d", no, sq ); return 0; } |
Output:-
In the above program, we have first initialized the required variable.
- no = it will hold the integer value.
- sq = it will hold the integer value.
Taking input number from the user to find the Square.
Calculating the Square of that number.
Printing output Square for that given number.