Advertisement
Guest User

Untitled

a guest
Feb 19th, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. unsigned long fact(int n, int k);
  4. unsigned long choose(int n, int k);
  5. int main()
  6. {
  7. int row;
  8.  
  9. unsigned long it = 1.0;
  10. unsigned long factor = 1.0;
  11. printf("Enter a row index: ");
  12. scanf("%d",&row);
  13. for(int i = 0; i<=row; i++) {
  14. it = 1.0;
  15. for(int j = 1; j<= i; j++) {
  16. factor = (row+1-j)/((unsigned long) j);
  17. it*=factor;
  18.  
  19. }
  20. printf("%lu",it);
  21. printf(" ");
  22. }
  23.  
  24.  
  25.  
  26. // Write your code here
  27.  
  28. return 0;
  29. }
  30.  
  31. unsigned long choose (int n, int k) {
  32. unsigned long a = 1;
  33. unsigned long b = 1;
  34. for(int i = n; i>=(n-k+1);i--) {
  35. a*=i;
  36.  
  37. }
  38. for(int j = 1; j<=k; j++) {
  39. b*=j;
  40. }
  41. unsigned long r = a/b;
  42. return r;
  43. }
  44. unsigned long fact(int n, int k) {
  45. if(n==k) {
  46. return 1;
  47. }
  48. unsigned long helper = 1.0;
  49. unsigned long val = 1.0;
  50. for(unsigned i = 1; i <= k; i++) {
  51. helper = (n+1-i)/i;
  52. val= val*helper;
  53. //this equation working is fake news
  54.  
  55. }
  56.  
  57. return val;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement