C Exercises: Calculate the sum of the series 1 +11 + 111 + 1111 + .. n terms
C For Loop: Exercise-26 with Solution
Write a program in C to find the sum of the series 1 +11 + 111 + 1111 + .. n terms.
Pictorial Presentation:

Sample Solution:
C Code:
#include <stdio.h>
void main()
{
int n,i;
long sum=0;
long int t=1;
printf("Input the number of terms : ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("%ld ",t);
if (i<n)
{
printf("+ ");
}
sum=sum+t;
t=(t*10)+1;
}
printf("\nThe Sum is : %ld\n",sum);
}
Sample Output:
Input the number of terms : 5 1 + 11 + 111 + 1111 + 11111 The Sum is : 12345
Flowchart:

C Programming Code Editor:
Improve this sample solution and post your code through Disqus.
Previous: Write a program in C to display the n terms of square natural number and their sum.
Next: Write a c program to check whether a given number is a perfect number or not.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
C Programming: Tips of the Day
How to use __FILE__ macro shows full path?
Try
#include<string.h> #define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) For Windows use '\\' instead of '/'.
Ref: https://bit.ly/3mOf045
- Weekly Trends
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
- JavaScript functions Exercises
- Python Tutorial
- Python Array Exercises
- SQL Cross Join
- C# Sharp Array Exercises
We are closing our Disqus commenting system for some maintenanace issues. You may write to us at reach[at]yahoo[dot]com or visit us at Facebook