338,445 views
18 votes
18 votes
Write a program to find all integer solutions to the equation 4x + 3y -9z = 5 for values of x, y, and z between 0 to 100.

User Amica
by
2.6k points

1 Answer

14 votes
14 votes

Answer:

Following are the code to the given question:

#include <iostream>//header file

using namespace std;

int main()//main method

{

int c= 0;//defining integer variable to count number of solutions

int x,y,z;//defining integer variable which is used in the loop

for (x = 0; x <= 100; x++)//defining for loop to x value

for (y = 0; y <= 100; y++)//defining for loop to y value

for (z = 0; z <= 100; z++)//defining for loop to z value

if (4 * x + 3 * y - 9 * z == 5)//use if to check given condition

{

c++;//increment count value

cout << "(" << x << "," << y << "," << z << ")";//print solutions

cout << (c % 11? " " : "\\");//use for add file solution in a row

}

cout << "\\\\There are " << c << " solution(s)\\";//print solution couts

return 0;

}

Output:

Please find the attached file.

Step-by-step explanation:

In the above-given code four integer variable "x,y,z, and c" is declared, in which "x,y, and z" is used in the for loop with the if conditional statement that checks the given condition and prints the solution and the "c" variable is used to counts the number of solution, and at the last, it uses the print method to print its values.

Write a program to find all integer solutions to the equation 4x + 3y -9z = 5 for-example-1
User Noobzie
by
2.0k points