Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- #include <math.h>
- using namespace std;
- void PlotTable(int n);
- double S(int n);
- const int n = 5;
- int main()
- {
- PlotTable(n);
- cout << "S = " << S(n) << endl;
- system("PAUSE");
- return 0;
- }
- void PlotTable(int n)
- {
- cout << "Table = [";
- for (int i = 1; i <= n; i++)
- {
- if (i == n)
- {
- cout << pow(10.0, i) - 1 << "]";
- break;
- }
- cout << pow(10.0, i) - 1 << ", ";
- }
- cout << endl;
- }
- double S(int n)
- {
- if (n == 1) return 9;
- return ( pow(10.0, n) - 1 ) + S(n - 1);
- }
Advertisement
Add Comment
Please, Sign In to add comment