Advertisement
STANAANDREY

bac 4/20/2022 4

Apr 20th, 2022
1,052
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.30 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int suma(int a, int b) {
  5.     int sum = 0;
  6.     for (int d = 1; d <= a && d <= b; d++) {
  7.         if (a % d == 0 && b % d == 0) {
  8.             sum += d;
  9.         }
  10.     }
  11.     return sum;
  12. }
  13.  
  14. int main() {
  15.     cout << suma(20, 12) << endl;//7
  16.     return 0;
  17. }
  18.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement