C program to find square root of a number; Through this tutorial, you will learn how to find the square root of a number in the c program with the help sqrt function and without function.
Algorithm and Programs to Find Root Square of a Number in C
Use the following algorithm and programs to find square root of a number in c with and without sqrt:
- Algorithm to Find Square Root of a Number
- C Program to Find Square Root of a Number using SQRT Function
- C Program To Find Square Root of a Number Without Using sqrt
Algorithm to Find Square Root of a Number
Use the following algorithm to write a program to find square root of a number; as follows:
- Step 1: Start Program
- Step 2: Read the number from user and store it in a.
- Step 3: Calculate square root of number a using sqrt function
- Step 4: Print square root of a number
- Step 5: Stop Program
C Program to Find Square Root of a Number using SQRT Function
#include<stdio.h> #include<math.h> int main() { int n; double v; printf("Enter a Number: "); scanf("%d",&n); v = sqrt(n); printf("Square Root of %d is %f",n,v); }
The output of the above c program; as follows:
Enter a Number: 16 Square Root of 16 is 4.000000
C Program To Find Square Root of a Number Without Using sqrt
// C Program To Find The Square Root of a Number Without Using Sqrt #include <stdio.h> #include <math.h> int main(){ double num, root; // Asking for Input printf("Enter a number: "); scanf("%lf", &num); root = pow(num, 0.5); printf("The Square Root of %.2lf is %.2lf.", num, root); return 0; }
The output of the above c program; as follows:
Enter a number: 16 The Square Root of 16.00 is 4.00.