- Related Questions & Answers
- Average numbers in array in C Programming
- Add minimum number to an array so that the sum becomes even in C programming
- Arithmetic Mean in C programming
- Concatenate a string given number of times in C++ programming
- Write a program to Delete a Tree in C programming
- Write a function that returns 2 for input 1 and returns 1 for 2 in C programming
- Ways to paint N paintings such that adjacent paintings don’t have same colors in C programming
- Surface Area and Volume of Hexagonal Prism in C programming
- Superperfect Number in C programming
- Super Prime in c programming
- Sums of ASCII values of each word in a sentence in c programming
- Sum triangle from an array in C programming
- C Programming for sum of the series 0.6, 0.06, 0.006, 0.0006, …to n terms
- Sum of the numbers up to N that are divisible by 2 or 5 in c programming
- Sum of the first N terms of the series 5,12, 23, 38…. in C Programming

Given is a sequence: 2,22,222,2222….. and we need to find the sum of this sequence. So we have to Go for the mathematical formula that is made to find the sum of the series,

The explanation of the formula goes in such a way that -

sum =[2+22+222+2222….] sum= 2*[1+11+111+1111….] Sum = 2/9[9+99+999+9999….] sum= 2/9 [10+100+1000+10000+.....] sum = 2/9[10+10^{2}+10^{3}+10^{4}+.....] sum=2/9*[(10^{n}-1-9n)/9]

#include <stdio.h> #include <math.h> int main() { int n = 3; float sum = 2*(pow(10, n) - 1 - (9 * n))/81; printf("sum is %d", sum); return 0; }

sum is 879

Advertisements