Advertisement
apl-mhd

uptoNtermsFact1/factsum

Sep 4th, 2016
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.03 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include<math.h>
  4.  
  5. /*
  6.  
  7.     12/3! + 23/4! + 34/5! + ........ ...... upto n terms.
  8.  
  9. */
  10.  
  11. int  square(int n){
  12.  
  13.     int i;
  14.     double sum = 0;
  15.  
  16.     for(i = 1; i <=n; i++){
  17.          //sum += pow(i, i+2 ) / factFunction(i+2);
  18.          //printf(" %d ^ %d = %lf / %lf =%lf \n",i,i+1, pow(i, i+1 ),factFunction(i+2), pow(i, i+1 ) / factFunction(i+2));
  19.         //printf(" %d ^ %d = %lf / %d = %lf \n",i, i+1, pow(i, i+1 ), factFunction(i+2), pow(i, i+1 ) / factFunction(i+2) );
  20.  
  21.         sum += pow(i, i+1 ) / factFunction(i+2);
  22.  
  23.          }
  24.  
  25.          printf("%lf", sum);
  26.  
  27.  
  28.         //printf(" %d ^ %d =  %.lf\n",i, i+1, pow(i, i+1));
  29.  
  30.  
  31.  
  32.  
  33.  
  34. return sum;
  35. }
  36.  
  37. int factFunction(int fact){
  38.  
  39.     int i;
  40.     double value =1;
  41.  
  42.     for( i = 1; i<=fact; i++){
  43.  
  44.         value = value * i;
  45.     }
  46.  
  47.    // printf("%lf\n", value);
  48.  
  49.  
  50.  
  51.  
  52. return value;
  53. }
  54.  
  55. int main()
  56. {
  57.  
  58.        // printf("%d\n", square(3));
  59.          square(3);
  60.  
  61.        //  printf("%d", factFunction(1+4));
  62.  
  63.     return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement