C program to find square of a number; In this tutorial, i am going to show you how to find the square of a number in the c program using function and normal formula.
Algorithm and Programs to Find Square of a Number in C
- Algorithm to Find Square of a Number
- C Program to Find Square of a Number using Formula
- C Program to Find Square of a Number using Function
Algorithm to Find Square of a Number
Use the following algorithm to write a program to find square of a number; as follows:
- Step 1: Start Program
- Step 2: Get the number from user and store it in a.
- Step 3: Find square of number a using formula or function
- Step 4: Show square of number
- Step 5: Stop Program
C Program to Find Square of a Number using Formula
#include<stdio.h> int main() { float number, square; printf("Please Enter any integer Value : "); scanf("%f", &number); square = number * number; printf("square of a given number %.2f is = %.2f", number, square); return 0; }
The result of the above c program; as follows:
Please Enter any integer Value : 20 square of a given number 20.00 is = 400.00
C Program to Find Square of a Number using Function
#include<stdio.h> //function to calculate square of number float squareOfNumber(float num) { return (num*num); } int main() { float number, square; printf("Please Enter any Value : "); scanf("%f", &number); square = squareOfNumber(number); printf("square of a given number %.2f is = %.2f", number, square); return 0; }
The result of the above c program; as follows:
Please Enter any Value : 10 square of a given number 10.00 is = 100.00