Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <cmath>
- #include <time.h>
- #include <stdlib.h>
- #define SPACE " "
- using namespace std;
- // Init Void
- int random(int min, int max);
- int fibonacci(int n);
- double factorielle(int n);
- int combinaison(int n, int p);
- void trianglePascal(int n);
- int main(void)
- {
- trianglePascal(4);
- system("pause");
- return 0;
- }
- int random(int min, int max)
- {
- if (min > max)
- {
- int temp = max;
- max = min;
- min = temp;
- }
- cout << min << SPACE << max << endl;
- srand(time(NULL));
- int val = (rand() % (max - min + 1) + min);
- return val;
- }
- int fibonacci(int n)
- {
- if (n <= 1) return n;
- else return fibonacci(n - 1) + fibonacci(n - 2);
- }
- double factorielle(int n)
- {
- int f = 1;
- for (int i = 1; i < n + 1; i++)
- {
- f *= i;
- }
- return f;
- }
- int combinaison(int n, int p)
- {
- return factorielle(n) / (factorielle(p) * factorielle(n - p));
- }
- void trianglePascal(int n)
- {
- cout << "Triangle de Pascal --- n = " << n << endl << 1 << endl;
- for (int i = 1; i < n + 1; i++)
- {
- for (int j = 0; j < i + 1; j++)
- {
- int currentVal = combinaison(i, j);
- cout << currentVal << SPACE;
- }
- cout << endl;
- }
- }
Add Comment
Please, Sign In to add comment