- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- 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

# C++ program to calculate how many years needed to get X rupees with 1% interest

Suppose we have a number X. We have 100 rupees in a bank. The bank returns annual interest rate of 1 % compounded annually. (Integers only). We have to check how many years we need to get X rupees?

So, if the input is like X = 520, then the output will be 213.

## Steps

To solve this, we will follow these steps −

sum := 0 balance := 100 while balance < n, do: interest := balance / 100 sum := sum + 1 balance := balance + interest return sum

## Example

Let us see the following implementation to get better understanding −

#include <bits/stdc++.h> using namespace std; int solve(int n){ int sum = 0; int balance = 100; while (balance < n){ int interest = balance / 100; sum = sum + 1; balance = balance + interest; } return sum; } int main(){ int X = 520; cout << solve(X) << endl; }

## Input

520

## Output

213

- Related Questions & Answers
- Java Program to calculate Simple Interest and Compound Interest
- Java Program to calculate Compound Interest
- Java Program to Calculate Simple Interest
- Java Program to Calculate the Compound Interest
- Python program to find ways to get n rupees with given coins
- C++ program to find maximum how many chocolates we can buy with at most k rupees
- Program to find how many swaps needed to sort an array in Python
- C++ program to find minimum how many operations needed to make number 0
- C++ program to find minimum how many coins needed to buy binary string
- C++ program to find the rate percentage from compound interest of consecutive years
- Program to find how many years it will take to reach t amount in Python
- C++ program to count at least how many operations needed for given conditions
- How to calculate age in years from birthdate in MySQL?
- C++ program to check the coins forms x amount of rupees or not
- Calculate compound interest in JavaScript

Advertisements