Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- int main()
- {
- int c;
- double a,b,i;
- cout<<"請輸入兩個數字以求最大公因數以及最小公倍數:"<<endl;
- cin>>a;
- cin>>b;
- while(i!=1)
- {
- if((a/i)-(int)(a/i)!=0&&(b/i)-(int)(b/i)!=0)
- {
- i++;
- }
- else
- {
- break;
- }
- }
- cout<<"最大公因數為:"<<i<<endl;
- while(i=1)
- {
- if((a/i)-(int)(a/i)!=0&&(b/i)-(int)(b/i)!=0)
- {
- i++;
- }
- else
- {
- break;
- }
- }
- cout<<"最大公因數為:"<<i<<endl;
- system("pause");
- return 0;
- }
Add Comment
Please, Sign In to add comment