Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int main(){
- int N,i,aux;
- float S;
- printf("\nDigite o valor de N: ");
- scanf("%d",&N);
- if(N==1){
- S=2;
- printf("\nA soma total tem valor %.2f\n\n",S);
- system("pause");
- }//end if
- else{
- aux=0;
- for(i=(N-1);i>=1;i--){
- S += (float)1/fatorial(N-aux);
- aux++;
- }//end for
- printf("\nA soma total tem valor %.3f\n\n",S+2);
- system("pause");
- }//end else
- }//end program
- int fatorial(int Num){
- int n,fat;
- if(Num>=0){
- fat=1;
- n=Num;
- while(n>0){
- fat*=n;
- n--; }//end while
- }//end if
- }//end fatorial()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement