Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int n, i, a, b, x, cmmdc, r;
- cout<<"Cate nr sa se citeasca?"; cin>>n;
- cout<<"Introduceti un numar:"; cin>>a; //primul nr
- cout<<"Introduceti un numar:"; cin>>b; //al doilea nr nr
- if(a==0 && b==0)
- cout<<"Cmmmdc nedefinit"<<endl;
- else
- {
- if(b==0)
- cmmdc=a;
- else
- {
- do
- {
- r=a%b;
- a=b;
- b=r;
- }
- while(r);
- cmmdc=a;
- }
- }
- for(i=1; i<=n-2; i++)
- {
- cout<<"Introduceti un numar:"; cin>>x;
- if(x==0)
- cmmdc=cmmdc;
- else
- {
- do
- {
- r=x%cmmdc;
- x=cmmdc;
- cmmdc=r;
- }
- while(r);
- cmmdc=x;
- }
- }
- cout<<"Cmmdc este:"<<cmmdc;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement