Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- #include <cstdlib>
- #include <fstream>
- #include <ctime>
- /*W pliku są pary liczb, napisz program który dla tych par obliczy ich NWW i wyświetli te liczby i ich NWW, zrób nwd rekurencyjnie*/
- using namespace std;
- int nww(int,int);
- int nwd_rek(int,int);
- int main(int argc, char** argv) {
- ifstream nazwa("liczby.txt");
- int liczba1,liczba2;
- while(!nazwa.eof())
- {
- nazwa>>liczba1>>liczba2;
- cout<<"Liczba 1: "<<liczba1<<"\nLiczba 2: "<<liczba2<<"\nNWW podanych liczb: "<<nww(liczba1,liczba2)<<"\nNWD podanych liczb: "<<liczba1/nwd_rek(liczba1,liczba2)*liczba2<<endl<<endl<<endl;
- }
- nazwa.close();
- return 0;
- }
- int nwd_rek(int fa,int fb)
- {
- if(fb==0)
- {
- return fa;
- }
- return nwd_rek(fb,fa%fb);
- }
- int nww(int fa, int fb)
- {
- int pom;
- while(fb!=0)
- {
- pom = fb;
- fb = fa%fb;
- fa = pom;
- }
- return fa;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement