#include <cmath> #include <iostream> int main() { double square, originalNumber; // Prompt the user for the square of a natural number std::cout << "Enter the square of a natural number: "; std::cin >> square; // Calculate the original number by taking the square root originalNumber = sqrt(square); // Calculate the square of the original number double resultSquare = (originalNumber + 1) * (originalNumber + 1); // Display the original number and its square std::cout << "Original Number: " << originalNumber << std::endl; std::cout << "Square of Original Number: " << resultSquare << std::endl; return 0; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter