Skip to content

Instantly share code, notes, and snippets.

@clive819
Created October 3, 2015 14:00
Show Gist options
  • Save clive819/7718840fb259c42a8b9f to your computer and use it in GitHub Desktop.
Save clive819/7718840fb259c42a8b9f to your computer and use it in GitHub Desktop.
#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