- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C Programming for Sum of sequence 2, 22, 222, ………
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+102+103+104+.....] sum=2/9*[(10n-1-9n)/9]
Example
#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; }
Output
sum is 879
Advertisements