Program to find square root of a number

Problem statement:-  Program to find the square root of a number.

Data requirement:-

  Input Data:- num

  Output Data:- sqrt(num)  

Program in C

Here is the source code of the C Program to find the square root of a number.

Code:

#include<stdio.h>
#include<math.h>
int main()
{
    printf("Enter the Number:");
    int num;
    scanf("%d",&num);
    printf("Square root of %d is : %0.2lf\n",num,sqrt(num));
}

Input/Output:
Enter the Number:25
Square root of 25 is: 5.00

Program in C++

Here is the source code of the C++ Program to find the square root of a number.

Code:

#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    cout<<"Enter the Number:";
    int num;
    cin>>num;
    cout<<"Square root of "<<num<<" is : "<<sqrt(num);
}

Input/Output:
Enter the Number:49
Square root of 49 is : 7

Program in Java
  
Here is the source code of the Java Program to find the square root of a number.

Code:

import java.util.Scanner;
public class SquareRootOfNumber {

public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
System.out.println("Enter the Number:");
    int num=cs.nextInt();
    System.out.println("Square root of "+num+" is : "+Math.sqrt(num));
     cs.close();
}
}

Input/Output:
Enter the Number:
70
Square root of 70 is : 8.366600265340756


Program in Python
  
Here is the source code of the Python Program to find the square root of a number.

Code:

import math
num=int(input("Enter the Number:"))
print("Square root of ",num," is : ",math.sqrt(num))

Input/Output:

Post a Comment

0 Comments