C++ program to take a number as input and calculate the square root of given number


Following program shows you how to take a number as input and calculate the square root of given number.
In this program we get input from user and calculate square root using sqrt(input) method

#include <iostream>
#include <math.h>

int main() {
	int input;
	std::cout << "Enter a number:";
	std::cin >> input;
	float result = sqrt(input);
	std::cout << "Input: " << input << "\n";
	std::cout << "Square Root of " << input << " is: " << result;
}

Output:

Enter a number: 4
Input: 4
Square Root of 4 is: 2