Created
October 3, 2015 14:00
-
-
Save clive819/7718840fb259c42a8b9f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <math.h> | |
#include <iomanip> | |
using namespace std; | |
int main(){ | |
int digits; | |
cout << "Enter the number of digits (taken from 2, 4, 6, 8): "; | |
cin >> digits; | |
int max = pow(10,digits) - 1, c = pow(10,digits/2); | |
for (int i=0; i <= max; i++) { | |
int a=i%c,b=i/c; | |
if (pow(a+b, 2) == i) { | |
cout << setw(digits) << setfill('0') << i << "\n"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment