In this example, i’ll show you How to find compound interest in C#.

This is a C# program that calculates the total amount of an investment over a number of years, given the initial amount, the rate of interest, the number of years, and the number of times per year that the interest is compounded.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
using System; namespace compund { class compound { static void Main(string[] args) { double Total = 0, interestRate, years, annualCompound, Amount; Console.Write("Enter the Initial Amount : "); Amount = Convert.ToDouble(Console.ReadLine()); Console.Write("Enter the Rate of Interest : "); interestRate = Convert.ToDouble(Console.ReadLine()) / 100; Console.Write("Enter the Number of Years : "); years = Convert.ToDouble(Console.ReadLine()); Console.Write("Number of Times the Interest will be Compounded : "); annualCompound = Convert.ToDouble(Console.ReadLine()); for (int t = 1; t < years + 1; t++) { Total = Amount * Math.Pow((1 + interestRate / annualCompound), (annualCompound * t)); Console.Write("Your Total for Year {0} " + "is {1:F0}. \n", t, Total); } Console.ReadLine(); } } } |

When the program is run, it prompts the user to enter the initial amount of the investment, the rate of interest, the number of years, and the number of times per year that the interest is compounded.

It then uses a loop to calculate the total amount of the investment for each year, based on the initial amount, the rate of interest, and the number of times per year that the interest is compounded. The total amount for each year is calculated using the formula:

Total = Amount * (1 + interestRate / annualCompound)^(annualCompound * t)

where Amount is the initial amount of the investment, interestRate is the rate of interest, annualCompound is the number of times per year that the interest is compounded, and t is the number of years.

The program then outputs the total amount for each year to the console and waits for the user to press the Enter key before ending.