Advertisement
Guest User

Untitled

a guest
Feb 10th, 2016
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. // ConsoleApplication2.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "iostream"
  6. using namespace std;
  7.  
  8. void n_po_k(int n, int k,int &w)
  9. {
  10. if (k == 0 || k == n)
  11. w=1;
  12. if (n > 0 && k > 0 && n > k)
  13. {
  14.  
  15. n_po_k(n - 1, k - 1, w);
  16. int a = w;
  17. n_po_k(n - 1, k, w);
  18. int b = w;
  19. w=b+a;
  20. }
  21. }
  22. int * gen_tab(int n)
  23. {
  24. int *tablica;
  25. tablica = (int*)malloc(sizeof(int)*n);
  26. int w;
  27. for (int i = 0; i <n; i++)
  28. {
  29. if (0 <i && i <=n)
  30. {
  31. n_po_k(n,i,w);
  32. tablica[n-i] = w;
  33. }
  34.  
  35. }
  36. return tablica;
  37. }
  38. int _tmain(int argc, _TCHAR* argv[])
  39. {
  40. int n = 10;
  41. int *tabliczka = gen_tab(n);
  42. for (int i = 0; i <n; i++)
  43. {
  44. cout << "Element nr:" << i<< "to: ";
  45. cout << tabliczka[i] << endl;
  46. }
  47. return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement