main.cpp
C++
#include <iostream>
#include <cmath> // Built-in math library
int main() {
double number, result;
std::cout << "Enter a number: ";
// Takes live input below
if (number < 0) {
std::cout << "Error: Negative input!";
} else {
result = std::sqrt(number);
std::cout << "Square root = " << result;
}
return 0;
}
💻 Live Execution Simulator
Click "Run Code" to view the program output...