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 find the sum of the series 1 +11 + 111 + 1111 + .. n terms
Q:

Write a program in C++ to find the sum of the series 1 +11 + 111 + 1111 + .. n terms

0

Write a program in C++ to find the sum of the series 1 +11 + 111 + 1111 + .. n terms

Sample Output:

 Display the sum of the series 1 +11 + 111 + 1111 + .. n terms:        
-------------------------------------------------------------------    
 Input number of terms: 5                                              
1 + 11 + 111 + 1111 + 11111                                            
 The sum of the series is: 12345  

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()
{
    int n, i, sum = 0;
    int t = 1;
    cout << "\n\n Display the sum of the series 1 +11 + 111 + 1111 + .. n terms:\n";
    cout << "-------------------------------------------------------------------\n";
    cout << " Input number of terms: ";
    cin >> n;
    for (i = 1; i <= n; i++) 
    {
        cout << t << " ";
        if (i < n) 
        {
            cout << "+ ";
        }
        sum = sum + t;
        t = (t * 10) + 1;
    }
    cout << "\n The sum of the series is: " << 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