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)  
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
please tell me how to write proofs for diophantine equation
please tell me how to write proofs for diophantine equation
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
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.
In c++ Write a program that reads a string consisting of a positive integer or a...
In c++ Write a program that reads a string consisting of a positive integer or a positive decimal number and converts the number to the numeric format. If the string consists of a decimal number, the program must use a stack to convert the decimal number to the numeric format. Use the STL stack
1. Does the Diophantine equation 3x−4y = 0 have an integer solution? If so, can you...
1. Does the Diophantine equation 3x−4y = 0 have an integer solution? If so, can you list all integer solutions? 2. Does the equation 3x − 4y = 5 have an integer solution? If so, can you list all the integer solutions?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT