Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- float factorial(int n)
- {
- if (n == 0) return 1 ;
- else return (n * factorial(n-1)) ;
- }
- int signal (int n)
- {
- int i , result = -1 ;
- for (i = 0 ; i < n ; i++) result *= -1 ;
- return result ;
- }
- float potencia(float x , int n)
- {
- int i ;
- float result = x ;
- for (i = 0 ; i < n - 1 ; i++) result *= x ;
- return result ;
- }
- float mod (float n)
- {
- if (n < 0) return (-n) ;
- else return (n) ;
- }
- float sen (float x , float t)
- {
- float termo = x , total = 0 ;
- int i = 2 ;
- while (mod(termo) > t)
- {
- total += termo ;
- termo = signal (i) * (potencia (x , 2 * i - 1) / factorial (2 * i - 1)) ;
- i++ ;
- }
- return total ;
- }
- int main ()
- {
- float x , t ;
- printf ("Qual é o valor de x? ") ;
- scanf ("%f" , &x) ;
- printf ("Qual o valor da tolerância? ") ;
- scanf ("%f" , &t) ;
- printf ("O seno de %.2f é %f\n" , x , sen(x , t)) ;
- return 0 ;
- }
Advertisement
Add Comment
Please, Sign In to add comment