Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- int gcd(int a, int b) {
- return b ? gcd(b, a % b) : a;
- }
- void findGcd(int* couples, int numCouples) {
- for (int i = 0; i < numCouples; i++) {
- printf("GCD of the %d%s%d%s", (i + 1), " couple: ", gcd(couples[2 * i], couples[2 * i + 1]), ".\n");
- }
- }
- int getNumber(int minValue, int maxValue) {
- int number;
- bool isCorrect;
- do {
- isCorrect = true;
- printf("\nEnter: ");
- scanf_s("%d", &number);
- if (number > maxValue || number < minValue) {
- printf("Your value will be more than %d%s%d%s", minValue, " and less than ", maxValue, ". Try again.");
- isCorrect = false;
- }
- } while (!isCorrect);
- return number;
- }
- void getCouples(int* couples, int numCouples) {
- for (int i = 0; i < numCouples; i++) {
- printf("Enter %d %s", (i + 1), "couple.");
- printf("\nEnter the first number of this couple.");
- couples[2 * i] = getNumber(1, INT_MAX);
- printf("Enter the second number of this couple.");
- couples[2 * i + 1] = getNumber(1, INT_MAX);
- }
- }
- int main() {
- int couples[50];
- printf("Enter the number of couples.");
- int numCouples = getNumber(1, 25);
- printf("Now enter couples.");
- getCouples(couples, numCouples);
- findGcd(couples, numCouples);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement