Apparcane

C++. Знайдіть найбільший спільний дільник (НСД) двох чисел

Dec 9th, 2024
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.29 KB | Source Code | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int gcd(int a, int b) {
  5.     while (b != 0) {
  6.         int temp = b;
  7.         b = a % b;
  8.         a = temp;
  9.     }
  10.     return a;
  11. }
  12.  
  13. int main() {
  14.     int num1 = 48, num2 = 18;
  15.     cout << "НСД: " << gcd(num1, num2) << endl;
  16.     return 0;
  17. }
  18.  
Tags: C++
Advertisement
Add Comment
Please, Sign In to add comment