
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
C/C++ Program to Find sum of Series with n-th term as n power of 2 - (n-1) power of 2
Here we will see how to get the sum of the series with n-th term as n2 – (n-1)2. The recurrence relation is like below −
Tn = n2 − (n−1)2
So the series is −
We need to find S mod (109 + 7), where S is the sum of all terms of the given series.
Example
#include<iostream> #define X 1000000007 using namespace std; long long getSum(long long n) { return ((n % X) * (n % X)) % X; } int main() { long long n = 56789; cout << getSum(n); }
Output
224990500
- Related Articles
- Find sum of Series with n-th term as n^2 - (n-1)^2 in C++
- C/C++ Program to Find the sum of Series with the n-th term as n^2 – (n-1)^2
- Java Program to Find sum of Series with n-th term as n^2 – (n-1)^2
- Python Program for Find sum of Series with the n-th term as n^2 – (n-1)^2
- Program to find N-th term of series 1, 2, 11, 12, 21… in C++
- C++ program to find n-th term of series 2, 10, 30, 68, 130 …
- C++ program to find the sum of the series 1 + 1/2^2 + 1/3^3 + …..+ 1/n^n
- Program to find N-th term of series 0, 0, 2, 1, 4, 2, 6, 3, 8…in C++
- Program to find N-th term of series 2, 4, 3, 4, 15… in C++
- C++ Program to find the sum of a Series 1/1! + 2/2! + 3/3! + 4/4! + …… n/n!
- C++ program to find the sum of the series 1/1! + 2/2! + 3/3! + 4/4! +…….+ n/n!
- Program to find N-th term of series 0, 2,1, 3, 1, 5, 2, 7, 3...in C++
- Sum of the series 1.2.3 + 2.3.+ … + n(n+1)(n+2) in C
- C++ Programe to find n-th term in series 1 2 2 3 3 3 4
- Program to find sum of series 1 + 2 + 2 + 3 + 3 + 3 + .. + n in C++

Advertisements