Ziomnexpl

nwd z txt do txt

Oct 21st, 2020 (edited)
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. /* run this program using the console pauser or add your own getch, system("pause") or input loop */
  5. using namespace std;
  6.  
  7. int NWD(int a,int b)
  8. {
  9.     int r;
  10.     r=a%b;
  11.     while(r!=0)
  12.     {
  13.         a=b;
  14.         b=r;
  15.         r=a%b;
  16.     }
  17.     return b;
  18. }
  19.  
  20.  
  21. int main(int argc, char** argv) {
  22.     int a,b;
  23.     ifstream odczyt("ryt.txt");
  24.     ofstream zapis("lul.txt");
  25.     odczyt>>a>>b;
  26.     cout<<a<<" "<<b;
  27.     cout<<endl<<"nwd wynosi "<<NWD(a,b);
  28.     zapis<<"nwd liczab "<<a<<" i "<<b<<" wynosi "<<NWD(a,b);
  29.     odczyt.close();
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment