Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Find all integer solutions to the equation x2 + y2 = 1600, where x >= 0 and y >=

ID: 3623784 • Letter: F

Question

Find all integer solutions to the equation x2 + y2 = 1600, where x >= 0 and y >= 0 and both x and y are within the range of the int data type. Do not list a solution that is the same as another solution, but with the numbers reversed.
To use exhaustive search for this problem, you will need to try pairs of values for x and y. While this can be done with a single loop, it may be more natural to use a nested loop (i.e., one loop included in the body of another loop).

***I am not allowed to use arrays*** (i've commented it out in my code)

This is what I have:

[code]

#include <stdio.h>
main ()
{
//int arrayCounter;
int x;
int y;

//need an array of 1600 elements
//int soln[1600];

int alreadyUsedX;
//arrayCounter = 0;
for (x = 0; x < 40; x++) {

for (y = 0; y < 40; y++) {
//printf("x=%d, y=%d ", x, y);

//soln[arrayCounter] = x*x + y*y;
//arrayCounter++;

if (((x*x) + (y*y)) == 1600) {
alreadyUsedX = x;
printf("alreadyUsedX=%d ", alreadyUsedX);
printf("y=%d ", y);
if (y == alreadyUsedX) {
//return;
} else {
printf("%d^2 x %d^2 = 1600 ", x, y);
}

}

}

}

/*int j;
for (j=0; j<1600; j++){

if (soln[j] == 1600) {
printf("index at %d index is 1600 ", j);
}
}*/

}
[/code]

Explanation / Answer

please rate - thanks

 

#include <stdio.h>
#include <conio.h>
#include <math.h>
main ()
{
int x;
int y;
int max;
max=sqrt(1600);
for (x = 0; x <= max; x++) {
for (y = 0; y <= max; y++) {
    if(y>x)
        if (((x*x) + (y*y)) == 1600) {
             printf("%d^2 + %d^2 = 1600 ", x, y);
}

}

}
getch();
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote