Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- unsigned long fact(int n, int k);
- unsigned long choose(int n, int k);
- int main()
- {
- int row;
- unsigned long it = 1.0;
- unsigned long factor = 1.0;
- printf("Enter a row index: ");
- scanf("%d",&row);
- for(int i = 0; i<=row; i++) {
- it = 1.0;
- for(int j = 1; j<= i; j++) {
- factor = (row+1-j)/((unsigned long) j);
- it*=factor;
- }
- printf("%lu",it);
- printf(" ");
- }
- // Write your code here
- return 0;
- }
- unsigned long choose (int n, int k) {
- unsigned long a = 1;
- unsigned long b = 1;
- for(int i = n; i>=(n-k+1);i--) {
- a*=i;
- }
- for(int j = 1; j<=k; j++) {
- b*=j;
- }
- unsigned long r = a/b;
- return r;
- }
- unsigned long fact(int n, int k) {
- if(n==k) {
- return 1;
- }
- unsigned long helper = 1.0;
- unsigned long val = 1.0;
- for(unsigned i = 1; i <= k; i++) {
- helper = (n+1-i)/i;
- val= val*helper;
- //this equation working is fake news
- }
- return val;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement