hozer

Recursion - LabApakA2

May 27th, 2014
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.42 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include <conio.h>
  5.  
  6. float x(int n)
  7. {
  8.     if (n <= 1) return 1;
  9.     return 0.3*x(n - 1);
  10. }
  11.  
  12. float y(int n)
  13. {
  14.     if (n <= 1) return 1;
  15.     return pow(x(n - 1), 2) + y(n - 1);
  16. }
  17.  
  18. int main()
  19. {
  20.     int n, i;
  21.     float sum = 0;
  22.     printf("input n: "); scanf("%d", &n);
  23.  
  24.  
  25.     for (i = 1; i <= n; i++)
  26.         sum += x(i) / (1 + y(i));
  27.  
  28.     printf("sum=%f", sum);
  29.     _getch();
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment