Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication2.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include "iostream"
- using namespace std;
- void n_po_k(int n, int k,int &w)
- {
- if (k == 0 || k == n)
- w=1;
- if (n > 0 && k > 0 && n > k)
- {
- n_po_k(n - 1, k - 1, w);
- int a = w;
- n_po_k(n - 1, k, w);
- int b = w;
- w=b+a;
- }
- }
- int * gen_tab(int n)
- {
- int *tablica;
- tablica = (int*)malloc(sizeof(int)*n);
- int w;
- for (int i = 0; i <n; i++)
- {
- if (0 <i && i <=n)
- {
- n_po_k(n,i,w);
- tablica[n-i] = w;
- }
- }
- return tablica;
- }
- int _tmain(int argc, _TCHAR* argv[])
- {
- int n = 10;
- int *tabliczka = gen_tab(n);
- for (int i = 0; i <n; i++)
- {
- cout << "Element nr:" << i<< "to: ";
- cout << tabliczka[i] << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement