C Exercises: Display the sum of the series [ 9 + 99 + 999 + 9999 ...]
21. Sum of Series [9 + 99 + 999 + …]
Write a program in C to display the sum of the series [ 9 + 99 + 999 + 9999 ...].
This C program calculates and displays the sum of a series where each term is formed by repeating the digit 9 (e.g., 9, 99, 999, 9999, ...). The program prompts the user for the number of terms (n) and then computes the sum using a loop that generates each term and adds it to the total sum. The final sum is then printed to the console.
Visual Presentation:
![Display the sum of the series [ 9 + 99 + 999 + 9999 ...]](https://www.w3resource.com/w3r_images/c-for-loop-image-exercises-21.png)
Sample Solution:
C Code:
Output:
Input the number or terms :5 9 99 999 9999 99999 The sum of the series = 111105
Flowchart:
![Flowchart: Display the sum of the series [ 9 + 99 + 999 + 9999 ...]](https://www.w3resource.com/w3r_images/c-for-loop-exercises-21.png)
For more Practice: Solve these Related Problems:
- Write a C program to generate the series 9, 99, 999, ... for n terms and compute their product.
- Write a C program to display the series 9, 99, 999, ... using string manipulation and then sum the series.
- Write a C program to calculate the sum of the series using arithmetic progression logic for digit repetition.
- Write a C program to generate the series and compute the average of the generated terms.
C Programming Code Editor:
Previous: Write a program in C to display the pattern like a pyramid using asterisk and each row contain an odd number of asterisks.
Next: Write a program in C to print the Floyd's Triangle.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.