Advertisement
C0BRA

Coolness

Feb 9th, 2012
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. #include <iostream>
  2. #include <functional>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     const int size = 10;
  9.    
  10.     function<unsigned long(unsigned long)> func;
  11.  
  12.     func = [&](unsigned long x) -> unsigned long
  13.     {
  14.         if(x <= 1)
  15.             return 1;
  16.         return x * func(x - 1);
  17.     };
  18.  
  19.     int ints[size];
  20.     for(int i = 0; i < size; i++)
  21.         ints[i] = func(i + 1);
  22.  
  23.     vector<int> vec (ints, ints + size);
  24.  
  25.     for(int x : vec)
  26.         printf("%i\n", x);
  27.  
  28.     printf("Sorting...\n");
  29.  
  30.     sort(vec.begin(), vec.begin() + size, [](int a, int b)
  31.     {
  32.         return a > b;
  33.     });
  34.  
  35.     for(int x : vec)
  36.         printf("%i\n", x);
  37.  
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement