In this C program we will learn to find square root using sqrt function. We will first take a number as input from user using scanf function then calculate square root of number by calling sqrt function of math.h header file.
Required Knowledge
C program to find square root of a number
#include <stdio.h> #include <math.h> int main () { double x, result; printf("Enter a number\n"); scanf("%lf", &x); result = sqrt(x); printf("Square root of %lf = %lf\n", x, result); return 0; }Output
Enter a number 49 Square root of 49.000000 = 7.000000
Enter a number 85.453 Square root of 85.453000 = 9.244079Related Topics