A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

Write a program in C++ to display the sum of the series [ 9 + 99 + 999 + 9999 ...]
Q:

Write a program in C++ to display the sum of the series [ 9 + 99 + 999 + 9999 ...]

0

Write a program in C++ to display the sum of the series [ 9 + 99 + 999 + 9999 ...]

Sample Output:

 Display the sum of the series [ 9 + 99 + 999 + 9999 ...]              
-------------------------------------------------------------          
 Input number of terms: 5                                              
9  99  999  9999  99999                                                
 The sum of the sarise = 111105   

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <iostream>
using namespace std;

int main()
{
    long int n, i, t = 9;
    int sum = 0;
    cout << "\n\n Display the sum of the series [ 9 + 99 + 999 + 9999 ...]\n";
    cout << "-------------------------------------------------------------\n";
    cout << " Input number of terms: ";
    cin >> n;

    for (i = 1; i <= n; i++) 
    {
        sum += t;
        cout << t << "  ";
        t = t * 10 + 9;
    }
    cout << "\n The sum of the sarise = " << sum << endl;
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now