#include %26lt;iostream%26gt;
using namespace std;
void main()
{
int i, j, k, l; // Counter variables
//-------------------- description object -----------------------------------
// Tell user what program does
cout %26lt;%26lt; "The following numbers indicate valid solutions to the lazy hobo\n";
cout %26lt;%26lt; "riddle.\n" %26lt;%26lt; endl;
//-------------------- end description object -------------------------------
//-------------------- computation object -----------------------------------
// Determine valid solutions to i*i + j*j + k*k + l*l = 200
for (i=1; i%26lt;=14; i++) {
for (j=1; j%26lt;=14; j++) {
for (k=1; k%26lt;=14; k++) {
for (l=1; l%26lt;=14; l++) {
if (i*i + j*j + k*k + l*l == 200) {
// Output valid number sequence
cout %26lt;%26lt; i %26lt;%26lt; " " %26lt;%26lt; j %26lt;%26lt; " " %26lt;%26lt; k %26lt;%26lt; " " %26lt;%26lt; l %26lt;%26lt; endl;
}
}
}
}
}
//-------------------- end computation object -------------------------------
Four hoboes riddle coding in c++ (how to apply the square root function) to the solution below?
if you want to make the output of i, j, k, or l the square root then put in the math.h header and just do cout%26lt;%26lt;sqrt(var) , i think that works
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment