Advertisement
kokokozhina

v1_2

Dec 15th, 2015
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. //используя рекурсию, найти n-ный член и сумму геометрической прогрессии, если известны её первый член и делитель
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. double num(double first, double q, int n)
  7. {
  8.     if (n == 1)
  9.         return first;
  10.     else   
  11.         return num(first, q, n - 1)*q;
  12. }
  13.  
  14. double sum(double first, double q, int n)
  15. {
  16.     if (n == 1)
  17.         return first;
  18.     else
  19.         return sum(first, q, n - 1) + num(first, q, n);
  20. }
  21.  
  22. int main()
  23. {
  24.     double first, q;
  25.     cin >> first >> q;
  26.     int n;
  27.     cin >> n;
  28.     cout << num(first, q, n) << " " << sum(first, q, n);
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement