Home » C programs » Sum of series C programs

Here, we are going to implement a **c program that will find the sum of series 1 + 11 + 111 + 1111 + ... N terms**.

Submitted by **IncludeHelp**, on March 04, 2018

**To find (calculate) the sum of series 1+11+111+1111+... till N terms using C program** - we are reading total number of terms by the user and using following steps:

- Declared variables to stores sum of the values (sum), loop counter (i) and a variable to store term (temp) value (like, 1, 11, 111,.. )
- Assigning 0 to the variable sum and initial value 1 to the temp
- Within the loop - first we are adding the temp value to the sum and them increasing the value of temp to make it next term value.
- And, after the loop – we are printing the value of the sum.

#include <stdio.h> int main() { int terms; //to store total terms int i; //to run loo; long int sum; //to store sum of values long int temp; //to add the diff or initial term value //assign 0 to sum and assign 1 as initial term value sum =0; temp =1; //input total terms printf("Enter total number of terms: "); scanf("%d",&terms); //run loop to find sum of each value //and then increase it with the differences for(i=0; i<terms; i++) { //print the value printf("%ld ", temp); //print '+' sign in the series if(i<terms-1) printf("+ "); //add the value and store in sum sum += temp; //update/increase the value temp = (temp*10)+1; } //print the value of sum of the series printf("\nSUM of the series is: %ld\n",sum); return 0; }

**Output**

First run: Enter total number of terms: 5 1 + 11 + 111 + 1111 + 11111 SUM of the series is: 12345 Second run: Enter total number of terms: 10 1 + 11 + 111 + 1111 + 11111 + 111111 + 1111111 + 11111111 + 111111111 + 1111111111 SUM of the series is: 1234567900

**Read more...**

Are you a blogger? Join our Blogging forum.

Comments and Discussions

.resCodeAS1 { display: block; width: 320px; height: 50px; }
@media(min-width: 300px) { .resCodeAS1 { display: none; } }
@media(min-width: 480px) { .resCodeAS1 { display: none; } }
@media(min-width: 750px) { .resCodeAS1 { display: block; width: 336px; height: 280px; } }
(adsbygoogle = window.adsbygoogle || []).push({});

(adsbygoogle = window.adsbygoogle || []).push({});

(adsbygoogle = window.adsbygoogle || []).push({});

solved programs: » C » C++ » DS » Java » C# |

aptitude que. & ans.: » C » C++ » Java » DBMS |

interview que. & ans.: » C » Embedded C » Java » SEO » HR |

Like other websites, this site uses cookies to deliver relevant ads based on your interest, by using our website, you acknowledge that you have read our privacy policy.

Close