vakho

[9, 99, 999, 9999, ...]

Nov 6th, 2012
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <math.h>
  4.  
  5. using namespace std;
  6.  
  7. void PlotTable(int n);
  8. double S(int n);
  9.  
  10. const int n = 5;
  11.  
  12. int main()
  13. {
  14.     PlotTable(n);
  15.     cout << "S = " << S(n) << endl;
  16.  
  17.     system("PAUSE");
  18.     return 0;
  19. }
  20.  
  21. void PlotTable(int n)
  22. {
  23.     cout << "Table = [";
  24.     for (int i = 1; i <= n; i++)
  25.     {
  26.         if (i == n)
  27.         {
  28.             cout << pow(10.0, i) - 1 << "]";
  29.             break;
  30.         }
  31.         cout << pow(10.0, i) - 1 << ", ";
  32.     }
  33.     cout << endl;
  34. }
  35.  
  36. double S(int n)
  37. {
  38.     if (n == 1) return 9;
  39.     return ( pow(10.0, n) - 1 ) + S(n - 1);
  40. }
Advertisement
Add Comment
Please, Sign In to add comment