C Program to enter any number and Calculate its Square Root
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
·
C
printf and scanf functions
·
sqrt
function of math.h library
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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
/*
* 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
Comments
Post a Comment