4. C Program to find Square Root of a given Number.
How does this program work?
- In this programme you will learn about how to do Square Root of a Number.
- The following code contains header for the sqrt function called #include <math.h>.
- The sqrt function returns the square root of x. If x is negative, the sqrt function will return a domain error.
Here is the code
#include <stdio.h>
#include <math.h>
int main(void)
{
int num ; //Initialise the variables
printf("Enter a number");
scanf("%d",&num);
float squareRoot; //Initialise square root using float variable
squareRoot = sqrt(num); //To compute square root using function sqrt()
printf("Square root of %d = %f", num, squareRoot);
return 0;
}