Advertisement
Guest User

Exercício 5

a guest
Nov 27th, 2014
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.83 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main(){
  5.    
  6.      int    N,i,aux;
  7.      float        S;
  8.    
  9.     printf("\nDigite o valor de N: ");
  10.     scanf("%d",&N);
  11.    
  12.     if(N==1){
  13.         S=2;
  14.        
  15.        printf("\nA soma total tem valor %.2f\n\n",S);  
  16.        system("pause");
  17.        
  18.         }//end if
  19.        
  20.         else{
  21.    
  22.     aux=0;
  23.     for(i=(N-1);i>=1;i--){
  24.    
  25.     S += (float)1/fatorial(N-aux);
  26.     aux++;
  27.     }//end for
  28.    
  29.     printf("\nA soma total tem valor %.3f\n\n",S+2);
  30.     system("pause");
  31.         }//end else
  32.     }//end program
  33.    
  34.    
  35. int fatorial(int Num){
  36.     int n,fat;
  37.    
  38.  
  39.       if(Num>=0){
  40.         fat=1;
  41.         n=Num;
  42.        
  43.             while(n>0){
  44.              fat*=n;
  45.              n--;     }//end while
  46.                 }//end if
  47. }//end fatorial()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement