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

AuthorDevendra Dode

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including 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. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

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