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.
1
Expert's answer
2011-11-25T08:17:38-0500
#include <iostream.h> void main(){ int A, B, minAB; int i; bool prime = true; cout<<"Enter number A: "; cin>>A; cout<<"Enter number B: "; cin>>B; if (A<=B) minAB = A; else minAB = B; i=2; 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"; }
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
Leave a comment