C Program to Find Square Root of a Number

C Program to Find Square Root of a Number

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.

AuthorAdmin

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

Your email address will not be published. Required fields are marked *