Advertisement
Guest User

Untitled

a guest
Jan 24th, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. int gcd(int a, int b) {
  4. return b ? gcd(b, a % b) : a;
  5. }
  6.  
  7. void findGcd(int* couples, int numCouples) {
  8. for (int i = 0; i < numCouples; i++) {
  9. printf("GCD of the %d%s%d%s", (i + 1), " couple: ", gcd(couples[2 * i], couples[2 * i + 1]), ".\n");
  10. }
  11. }
  12.  
  13. int getNumber(int minValue, int maxValue) {
  14. int number;
  15. bool isCorrect;
  16. do {
  17. isCorrect = true;
  18. printf("\nEnter: ");
  19. scanf_s("%d", &number);
  20. if (number > maxValue || number < minValue) {
  21. printf("Your value will be more than %d%s%d%s", minValue, " and less than ", maxValue, ". Try again.");
  22. isCorrect = false;
  23. }
  24. } while (!isCorrect);
  25. return number;
  26. }
  27.  
  28.  
  29. void getCouples(int* couples, int numCouples) {
  30. for (int i = 0; i < numCouples; i++) {
  31. printf("Enter %d %s", (i + 1), "couple.");
  32. printf("\nEnter the first number of this couple.");
  33. couples[2 * i] = getNumber(1, INT_MAX);
  34. printf("Enter the second number of this couple.");
  35. couples[2 * i + 1] = getNumber(1, INT_MAX);
  36. }
  37. }
  38.  
  39. int main() {
  40. int couples[50];
  41. printf("Enter the number of couples.");
  42. int numCouples = getNumber(1, 25);
  43. printf("Now enter couples.");
  44. getCouples(couples, numCouples);
  45. findGcd(couples, numCouples);
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement