Question

In: Computer Science

Write a Diophantine Equation program in C++. Find integer solutions to Ax + By = GCD...

Write a Diophantine Equation program in C++.

Find integer solutions to Ax + By = GCD (A, B)

Ex:

a = 3, b = 6, c = 9

a = 2, b = 5 , c = 1

Solutions

Expert Solution

​​​​​​

#include <bits/stdc++.h>

using namespace std;

int gcd(int a,int b) //function for find the GCD of 2 numbers

{

if(a%b==0)

return abs(b); //it returns the absolute Integer value

else

return gcd(b,a%b);

}  

bool isPossible(int a,int b,int c) //chekcs if integral solutions are possible

{

if(c%gcd(a,b)==0)

return true;

else

return false;

}

int main()

{

int a,b,c;

cout<<"enter the values of a,b,c:\n"; //taking input

cin>>a;

cin>>b;

cin>>c;

if(isPossible(a,b,c)) //checks possible or not

{

cout<<"possible\n";

}

else

cout<<"not possible\n";

}

Note : abs() - it's a build-in-function, returns the absolute Integer value.

Note : for indentation,pls look at screen shot.


Related Solutions

2.) By Theorem 3.23 of the text, the linear diophantine equation of the form ax +...
2.) By Theorem 3.23 of the text, the linear diophantine equation of the form ax + by = c has no integral solutions if c is not divisible by (a, b), the greatest common divisor of a and b. On the other hand if (a, b) divides c, then we can use the Extended Euclidean Algorithm to find integers s, t such that sa + tb = (a, b); multiplying through by the correct factor gives an integral solution x,...
Show that he gcd of 63 and 40 is 1 and find all integer solutions: 63s...
Show that he gcd of 63 and 40 is 1 and find all integer solutions: 63s + 40t = 1. Use the Euclidean algorithm to find the gcd. Then back solve to find s and t. To get full credit, use the format shown in the post below titled Bezout's Theorem. (See the example where we find the gcd of 18 and 5.) Bézout's theorem says "If  d is the gcd of m and n then we can find integers s...
Draw a Flow chart and write a C++ program to solve the quadratic equation ax^2 +...
Draw a Flow chart and write a C++ program to solve the quadratic equation ax^2 + bx + c = 0 where coefficient a is not equal to 0. The equation has two real roots if its discriminator d = b2 – 4ac is greater or equal to zero. The program gets the three coefficients a, b, and c, computes and displays the two real roots (if any). It first gets and tests a value for the coefficient a. if...
Find the equation of line passing through the pair of points . Write the equation in the form of Ax+By=C . (2,3) (1,-4)
Find the equation of line passing through the pair of points . Write the equation in the form of Ax+By=C . (2,3) (1,-4)  
please tell me how to write proofs for diophantine equation
please tell me how to write proofs for diophantine equation
Find all integer solutions to the equation: a) 105x + 83y = 1 b) 105x +...
Find all integer solutions to the equation: a) 105x + 83y = 1 b) 105x + 83y = 8
find the integer solutions to A^2 + 2*B^2 = C^2?
find the integer solutions to A^2 + 2*B^2 = C^2?
Write a C++ program that solves a quadratic equation to find its roots. The roots of...
Write a C++ program that solves a quadratic equation to find its roots. The roots of a quadratic equation ax2 + bx + c = 0 (where a is not zero) are given by the formula (–b ± sqrt(b2 – 4ac)) / 2a *Use #include for the use of sqrt. The value of the discriminant (b2 – 4ac) determines the nature of roots. If the value of the discriminant is zero, then the equation has a single real root. If...
Find the general form of all (integer) solutions for the equation 22x+48y+4z = 18.
Find the general form of all (integer) solutions for the equation 22x+48y+4z = 18.
Write a program usingif-elseif-else statements to calculate the real roots of a quadratic equation ax^2+bx+c=0
Write a program usingif-elseif-else statements to calculate the real roots of a quadratic equation ax^2+bx+c=0
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT