Advertisement
Dani_info

cmmdc a n nr

Dec 7th, 2017
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.11 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.      int n, i, a, b, x, cmmdc, r;
  8.         cout<<"Cate nr sa se citeasca?"; cin>>n;
  9.         cout<<"Introduceti un numar:"; cin>>a;  //primul nr
  10.         cout<<"Introduceti un numar:"; cin>>b;  //al doilea nr nr
  11.         if(a==0 && b==0)
  12.             cout<<"Cmmmdc nedefinit"<<endl;
  13.         else
  14.         {
  15.             if(b==0)
  16.                cmmdc=a;
  17.             else
  18.             {
  19.                 do
  20.                 {
  21.                     r=a%b;
  22.                     a=b;
  23.                     b=r;
  24.                 }
  25.                 while(r);
  26.                 cmmdc=a;
  27.             }
  28.         }
  29.  
  30.  
  31.       for(i=1; i<=n-2; i++)
  32.       {
  33.          cout<<"Introduceti un numar:"; cin>>x;
  34.  
  35.             if(x==0)
  36.                cmmdc=cmmdc;
  37.             else
  38.             {
  39.                 do
  40.                 {
  41.                     r=x%cmmdc;
  42.                     x=cmmdc;
  43.                     cmmdc=r;
  44.                 }
  45.                 while(r);
  46.                 cmmdc=x;
  47.             }
  48.  
  49.  
  50.       }
  51.       cout<<"Cmmdc este:"<<cmmdc;
  52.  
  53.  
  54.  
  55.     return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement