Advertisement
Guest User

nwd

a guest
Oct 25th, 2014
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #include<iostream>
  2.     using namespace std;
  3.      
  4.     int NWD (int a, int b)
  5.     {
  6.     int c;
  7.     while (b != 0)
  8.     {
  9.     c = a % b;
  10.     a = b;
  11.     b = c;
  12.     }
  13.     return a;
  14.     }
  15.      
  16.     /////////////////////////
  17.      
  18.      
  19.     int main()
  20.     {
  21.     int size=0,nwd[4],temp=0;
  22.     cin>>size;
  23.     while(size>0){
  24.     int tab[4];
  25.     for (int i=0; i<4; i++) cin>>tab[i];
  26.     nwd[0]=NWD(tab[0],tab[1]);
  27.     temp=nwd[0];
  28.      
  29.     for (int m=0; m<3; m++)
  30.     {
  31.     temp=NWD(nwd[m],tab[m+1]);
  32.     nwd[m+1]=temp;
  33.     }
  34.      
  35.     cout << temp<< endl;
  36.     temp=0;
  37.     nwd[0]=0;
  38.     tab[0]=0;
  39.     --size;
  40.     }
  41.     return 0;
  42.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement