Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Program to find N-th term of series 3, 5, 33, 35, 53… in C++
In this tutorial, we will be discussing a program to find N-th term of series 3, 5, 33, 35, 53…
For this, we will be provided with a number. Our task is to find the term for the given series at that particular position.
Example
#include <bits/stdc++.h>
using namespace std;
//finding the nth term in the series
int printNthElement(int n){
int arr[n + 1];
arr[1] = 3;
arr[2] = 5;
for (int i = 3; i <= n; i++) {
if (i % 2 != 0)
arr[i] = arr[i / 2] * 10 + 3;
else
arr[i] = arr[(i / 2) - 1] * 10 + 5;
}
return arr[n];
}
int main(){
int n = 6;
cout << printNthElement(n);
return 0;
}
Output
55
Advertisements