Advertisement
Guest User

Untitled

a guest
May 27th, 2015
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.57 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <iostream>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <math.h>
  6.  
  7. double integral(int n, double x)  
  8. {
  9.     if (n == 1)
  10.         return -cos(x);
  11.     if (n == 2)
  12.         return (x/2)-((1/4)*sin(2*x));
  13.     if (n > 2)
  14.         return -(pow(sin(x), n-1)*cos(x))/n + ((n-1)/n)*integral(n-2, x);
  15. }
  16.  
  17. int main()
  18. {
  19.     double x = 0.0; int n = 0;
  20.     printf("%s", "Enter x: \n");
  21.     scanf("%lf", &x);
  22.  
  23.     printf("%s", "Enter n: \n");
  24.     scanf("%d", &n);
  25.  
  26.     double result = integral(n, x);
  27.     printf("%s %f","Result: ",result);
  28.     getchar();
  29.     getchar();
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement