Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int nwd(int a, int b)
- {
- int x;
- int y;
- if (a<b) {y=a;}
- else y=b;
- for(x=y; x>0;--x){
- if((a%x==0)&&(b%x==0)) return x; }
- }
- int main()
- {
- cout<<"NWD(2,3) = "<<nwd(2,3)<<endl;
- cout<<"NWD(10,15) = "<<nwd(10,15)<<endl;
- cout<<"NWD(1000,104) = "<<nwd(1000,104)<<endl;
- cout<<"NWD(9,81) = "<<nwd(9,81)<<endl;
- return 0;
- }
Add Comment
Please, Sign In to add comment