C Program to Find Square Root of a Number

C program to find square root of a number; In this tutorial, i am going to show you how to find the square root of a number in the c program using sqrt function and without function.

Algorithm and Programs to Find Root Square of a Number in C

  • 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

Follow 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 result 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 result of the above c program; as follows:

Enter a number: 16
The Square Root of 16.00 is 4.00.

Be First to Comment

Leave a Reply

Your email address will not be published.