Header Ads Widget

C PROGRAM: Program to display the sum of the series [ 9 + 99+ 999 + 9999 ...] in C Language - Sparsh Blog

 Ans:->



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

Program is as follows:--


#include <stdio.h>

void main()

{

long int n,i,t=9;

int sum =0;

printf("Input the number or terms :");

scanf("%ld",&n);

for (i=1;i<=n;i++)

{

sum +=t;

printf("%ld ",t);

t=t*10+9;

}

printf("\nThe sum of the series = %d \n",sum);

}


OUTPUT:--


Input the number or terms : 5

9    99    999    9999    99999

The sum of the series - 111105    



MATHEMATICAL EXPLANATION OF IT IS AS FOLLOWS:-

Step-by-step explanation is:

In the ques,

we have to find out the sum of 'n' terms of the series,

9 + 99 + 999 + 9999 + .......upto n terms

So,

For finding the sum of the given series, we can write it as,

= (10 - 1) + (100 - 1) + (1000 - 1) + .................

= (10 - 1) + (10^2 - 1) + (10^3 - ) + .................

= (10 + 10^2 + 10^3 + .............. + 10^n) - (1 + 1 + 1 + ............n terms)


From the sum of the GP we can say that:-

Sum = 10(10^n - 1)/(10 - 1) = 10(10^n - 1)/9


Also,

Sum of  'n' number of 1 is = n

Now,


The sum of the given series will be:

Sum = (10^n - 1)/9 - n

Sum = (10^(n+1) - 9n - 10)/9

Sum = (10^(n+1) - 9n - 10)/9



Therefore the required sum of the series will be:-

Sum = (10^n+1) - 9n - 10)/9


Do You Know the answer for this question:-

Click on the Link for the Answer 👇👇

C EXERCISE: Program to convert positive integer number to its binary equivalent in C Language:-----


THANKU FOR READING THIS ARTICLE ON-


If you want to suggest any changes in the program please feel free to contact us in the comment section or you can reach us using Contact us Page.



Post a Comment

1 Comments

If you want to give any suggestion regarding the post please feel free to Comment below-