Advertisement
Guest User

Wyznaczanie NWD za pomocą szablonów

a guest
Oct 28th, 2011
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. using namespace std;
  4.  
  5. template <unsigned A, unsigned B>
  6. struct pNWD
  7.  {
  8.   enum
  9.    {
  10.     wartosc = pNWD<B, A%B>::wartosc
  11.    };
  12.  };
  13.  
  14. template <unsigned A>
  15. struct pNWD<A, 0>
  16.  {
  17.   enum
  18.    {
  19.     wartosc = A
  20.    };
  21.  };
  22.  
  23. template <unsigned A, unsigned B>
  24. struct MAX
  25.  {
  26.   enum
  27.    {
  28.     w=(A>B) ? A : B
  29.    };
  30.  };
  31.  
  32. template <unsigned A, unsigned B>
  33. struct MIN
  34.  {
  35.   enum
  36.    {
  37.     w=(A<B) ? A : B
  38.    };
  39.  };
  40.  
  41. template <unsigned A, unsigned B>
  42. struct NWD
  43.  {
  44.   enum
  45.    {
  46.     wartosc = pNWD< MAX<A, B>::w, MIN<A, B>::w >::wartosc
  47.    };
  48.  };
  49.  
  50.  
  51. int main()
  52. {
  53.  cout<<NWD<23*123, 23*997>::wartosc<<endl;
  54.  getch();
  55. }
  56.  
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement