program to calculate square root of a number using sqrt()

Description

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Square root of a number can be calculated using predefined sqrt() function.
sqrt() is a predefined function in math.h header file, it is used for
calculate square root of any number.
Square root of a number can be calculated using predefined sqrt() function. sqrt() is a predefined function in math.h header file, it is used for calculate square root of any number.
Square root of a number can be calculated using predefined sqrt() function.

sqrt() is a predefined function in math.h header file, it is used for 
calculate square root of any number.

C/C++

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
/* C Program to calculate square root of a number using - sqrt() */
//Save it as SquareRootOfNumberUsingSqrtFunction.c
#include<stdio.h>
#include<math.h>
int main(){
double num, squareRoot;
printf("Enter a number : ");
scanf("%lf",&num);
squareRoot = sqrt(num);
printf("The square root of %lf is %lf", num, squareRoot);
return 0;
}
/* C Program to calculate square root of a number using - sqrt() */ //Save it as SquareRootOfNumberUsingSqrtFunction.c #include<stdio.h> #include<math.h> int main(){ double num, squareRoot; printf("Enter a number : "); scanf("%lf",&num); squareRoot = sqrt(num); printf("The square root of %lf is %lf", num, squareRoot); return 0; }
/* C Program to calculate square root of a number using - sqrt() */
//Save it as SquareRootOfNumberUsingSqrtFunction.c

#include<stdio.h>
#include<math.h>
int main(){

    double num, squareRoot;

    printf("Enter a number : ");
    scanf("%lf",&num);

    squareRoot = sqrt(num);

    printf("The square root of %lf is %lf", num, squareRoot);

    return 0;
}
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Input:
Enter a number : 20
Output:
The square root of 20.0 is 4.47213595499958
Input: Enter a number : 20 Output: The square root of 20.0 is 4.47213595499958
Input:
Enter a number : 20

Output:
The square root of 20.0 is 4.47213595499958

Java

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
/* Java Program to calculate square root of a number using - sqrt() */
//Save it as SquareRootOfNumberUsingSqrtFunction.java
import java.io.*;
import java.util.Scanner;
public class SquareRootOfNumberUsingSqrtFunction {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter a number : ");
double num = scanner.nextDouble();
double squareRoot = Math.sqrt(num);
System.out.println("The square root of "+num+" is "+squareRoot);
}
}
/* Java Program to calculate square root of a number using - sqrt() */ //Save it as SquareRootOfNumberUsingSqrtFunction.java import java.io.*; import java.util.Scanner; public class SquareRootOfNumberUsingSqrtFunction { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("Enter a number : "); double num = scanner.nextDouble(); double squareRoot = Math.sqrt(num); System.out.println("The square root of "+num+" is "+squareRoot); } }
/* Java Program to calculate square root of a number using - sqrt() */
//Save it as SquareRootOfNumberUsingSqrtFunction.java

import java.io.*;
import java.util.Scanner;

public class SquareRootOfNumberUsingSqrtFunction {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        
        System.out.println("Enter a number : ");
        double num = scanner.nextDouble();
        
        double squareRoot = Math.sqrt(num);
        
        System.out.println("The square root of "+num+" is "+squareRoot);
    }
}
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Input:
Enter a number :
20
Output:
The square root of 20.0 is 4.47213595499958
Input: Enter a number : 20 Output: The square root of 20.0 is 4.47213595499958
Input:
Enter a number : 
20

Output:
The square root of 20.0 is 4.47213595499958

Related Programs

1) Program to calculate square root of a number without using standard library function 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)
Share Me

Leave a Reply