C Program to Find Square Root of a Number using sqrt Function

  • Write a c program to read a number and find square root using sqrt function.

Required Knowledge


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.


C program to find square root of a number

/*
* C program to calculate square root of a number 
* using sqrt function
*/
#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.244079

Related Topics
C program to find all roots of quadratic equationp
C program to check whether a number is prime or not
C program to add digits of a number
C program to count number of digits in an integer
C program to find sum of digits of a number using recursion
C program to reverse a number using recursion
C program to calculate power of a number
C program to generate random numbers
C program to convert string to integer
List of all C programs