76 289
Assignments Done
Successfully Done
In May 2019

Answer to Question #5289 in C++ for aimelawan

Question #5289
3. Make a program that determines whether two input numbers are coprime or not. Two numbers are coprime if the only positive number that perfectly divides them is 1. In other words, two numbers can be coprime only if their gcd is 1.
Expert's answer

#include <iostream.h>
void main(){
int A, B, minAB;
int i;
bool prime = true;
cout<<"Enter number A: ";
cout<<"Enter number B: ";
if (A<=B) minAB = A;
else minAB = B;
while ((i<=minAB)&&(prime==true)){
& if ((A%i==0)&&(B%i==0)) prime = false;
& i++;
if (prime == true) cout<<"A and B are coprime.";
else cout<<"A and B are not coprime.\r\n";

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!


No comments. Be first!

Leave a comment

Ask Your question

Privacy policy Terms and Conditions