Facebook
From Wojtek legieta kl.1P, 4 Years ago, written in C++.
This paste is a reply to Zad.8 from Wojtek legieta kl.1P - view diff
Embed
Download Paste or View Raw
Hits: 187
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int nwd(int x, int y)
  6. {
  7.     if (y==0) {
  8.             cout << "Liczba y nie moze rownav sie 0";
  9.             return 0;
  10.     }
  11.     else if (x%y==0) return y;
  12.     else return nwd(y,x%y);
  13. }
  14.  
  15. int main()
  16. {
  17.     int Nr1,Nr2;
  18.     cout << "Program liczy NWD dwóch podanych cyfr x oraz y" << endl;
  19.     cout << "Podaj x:";
  20.     cin >> Nr1;
  21.     cout << "Podaj y:";
  22.     cin >> Nr2;
  23.     if (nwd(Nr1,Nr2)!=0)
  24.     {
  25.         cout << "Nwd wynsoi podanych liczb wynosi:"<< nwd(Nr1,Nr2) << endl;
  26.     }
  27.  
  28. }
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.