In this article, we are going to learn how to find the square root of a number. A square root of a number is a value that, when multiplied by itself, gives the number. We will learn about the sqrt() function which is available in C standard library. The header file required for this function is.
C language sqrt() function
The sqrt() function takes a single argument in double and returns its square root. Let us see our code example to calculate the square root of a number.
syntax of sqrt() function is:
double sqrt(double arg);
- “Hello, World!” Program in C Language
- C Program to take input from users and print
- C Program to Add or Subtract two Integers
- C Program to Multiply and Divide Two Numbers
- C Program to Find Size of int, float,double, char, structure
- C Program to Find ASCII Value of Character
- C Program to Check Even or Odd Number
- C Program to Swap two numbers
Program to find the Square Root of a Number in C
#include<stdio.h>
#include<math.h>
int main()
{
double number;
double result;
printf("Please enter the number: ");
scanf("%lf",&number);
result = sqrt(number);
printf("The Square root of %d is %.2lf",number , result);
return 0;
}
Output
Please enter the number: 9
The Square root of 9.00 is 3.00