SHARE
TWEET

1.c

Wazedrifat Nov 13th, 2019 94 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2.  
  3. int factorial(int n) {
  4.     int fac = 1;
  5.  
  6.     for (int i = 1; i <= n; i++){
  7.         fac = fac * i;
  8.     }
  9.     return fac;
  10. }
  11.  
  12. int main(){
  13.     int n;
  14.     scanf("%d", &n);
  15.  
  16.     int sum = 0;
  17.  
  18.     printf("1!/1 ");
  19.     sum += factorial(1) / 1;
  20.  
  21.     for (int i = 2; i <= n; i++) {
  22.         printf("+ %d!/%d ", i, i);
  23.         sum += factorial(i) / i;
  24.     }
  25.  
  26.     printf(" = %d\n", sum);
  27. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top