Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.01 KB | None | 0 0
  1. /*
  2.  * File:   main.c
  3.  * Author: alumno
  4.  *
  5.  * Created on 31 de octubre de 2014, 12:39
  6.  */
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10.  
  11. /*
  12.  *
  13.  */
  14. int N,i,a,s;
  15. double x,ans;
  16.  
  17. double potencia(double x,int N){
  18.     double x1;
  19.     i=1;
  20.     x1=x;
  21.             while(i<N){
  22.          
  23.                 x1=x*x1;
  24.                 i++;
  25.                 ans=x1;
  26.                    }
  27.     return(ans);
  28.  
  29. }
  30.  
  31. long factorial(int N){
  32.     a=N;
  33.     i=a-1;
  34.     while(i>0){
  35.         a=a*i;
  36.         i--;
  37.     }
  38.     return(a);
  39. }
  40. int main(int argc, char** argv) {
  41.    
  42.     double resultado,termino,suma,terminoabs;
  43.     printf("Introduce el ángulo en radianes:");
  44.     scanf("%lf",&x);
  45.      N=2;
  46.      s=1;
  47.     termino=1;
  48.     while(termino>0.0005){
  49.         termino=(potencia(x,N))/(factorial(N));        
  50.         resultado=resultado+termino*s;
  51.         N=N+2;
  52.         s=s*(-1);
  53.        
  54.     }
  55.     resultado=1-resultado;
  56.     printf("La solucion es: %lf",resultado);
  57.    
  58.    
  59.    
  60.    
  61.    
  62.    
  63.  
  64.     return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement