C program to find the square root of a number. In the world of programming mastering fundamental mathematical operations is crucial for developing efficient and effective applications. IOne such operation is finding the square root of a number. In this articl,e we will wriyte a simple C program that calculates the square root of a given number.
Table of Contents
Square Root of a Number
The square root of a number is a value that, when multiplied by itself, gives the original number. For Example- The square root of 64 is 8 because 8×8 is 64.
C Program for Calculating Square Root
Let’s write a C program that calculates the square root of a given number.
#include <stdio.h>
#include <math.h>
void main()
{
float number, squareroot;
printf("Enter the number ");
scanf("%f", &number);
if (number<0)
{
printf("Error: Please enter a non negative number");
return;
}
squareroot = sqrt(number);
printf("The square root of %f is %f\n", number, squareroot);
}
Output
The above program calculates the square root of a given number by using the sqrt()
function from math.h
library.
Happy Coding
4 thoughts on “C Program to Find Square Root of a Number”