C Program to Find Square of a Number

C Program to Find Square of a Number

C program to find square of a number; Through this tutorial, you will learn how to find the square of a number in the c program with the help of function and normal formula.

Algorithm and Programs to Find Square of a Number in C

Let’s use the following algorithm and program 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: Read the number from user and store it in a.
  • Step 3: Calculate square of number a using formula or function
  • Step 4: Print 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 output 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 output of the above c program; as follows:

Please Enter any  Value : 10
square of a given number 10.00 is  =  100.00

Recommended C Programs

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Python, Javascript, JQuery, Laravel, Livewire, Codeigniter, Node JS, Express JS, Vue JS, Angular JS, React Js, MySQL, MongoDB, REST APIs, Windows, Xampp, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

Your email address will not be published. Required fields are marked *