Description
Follow the below program to find square root of a number without using standard library function - sqrt()
C/C++
/* C Program to calculate square root of a number without using standard library function - sqrt() */ //Save it as SquareRootOfNumber.c #include<stdio.h> int main() { int n; float i; printf("Enter a number : "); scanf("%d",&n); for(i=0.00000;i*i<n;i+=0.00001); printf("The square root of %d is %f",n,i); return 0; }
Input: Enter a number : 24 Output: The square root of 24 is 4.8989863
Java
/* Java Program to calculate square root of a number without using standard library function - sqrt() */ //Save it as SquareRootOfNumber.java import java.io.*; import java.util.Scanner; public class SquareRootOfNumber { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("Enter a number : "); int num =scanner.nextInt(); float i; for(i=0.00000f;i*i<num;i+=0.00001); System.out.println("The square root of "+num+" is "+i); } }
Input: Enter a number : 24 Output: The square root of 24 is 4.8989863
Related Programs
1) Program to calculate square root of a number using sqrt()2) Program to calculate power of a number using recursion
3) Program to Display Fibonacci Series using Recursion
4) Program to find HCF using Recursion
5) Program to find sum of digits of a number
6) Program to reverse a number
7) Program to convert Binary to Decimal
8) Program to convert Octal to Decimal
9) Program to calculate square root of a number without using standard library function sqrt()
10) Program to find HCF(Highest Common Factor)/GCD(Greatest Common Divisor) and LCM(Least Common Multiple)