C# Program to Find Compound Interest

This is a C# Program to calculate compound interest.

Problem Description

This C# Program Calculates Compound Interest.

Problem Solution

Compounding of interest allows a principal amount to grow at a faster rate than simple interest, which is calculated as a percentage of only the principal amount.

Program/Source Code

Here is source code of the C# Program to Calculate Compound Interest. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.

/*
 * C# Program to Calculate Compound Interest
 */
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();
        }
    }
}
Program Explanation

In this C# program, library function defined in <math.h> header file is used. We are reading the initial amount, the rate of interest, and the number of years using ‘Amount’, ‘InterestRate’, ‘Years’ variables respectively. For loop is used to compute the compound interest using the following formula:
Compound Interest = Principal amount (1 + InterestRate/Years) ^ (Years * number of times).

advertisement
advertisement
Runtime Test Cases
 
Enter the Initial Amount : 1000
Enter the Rate of Interest : 2
Enter the Number of Years : 2
Number of Times the Interest will be Compounded : 2
Your Total for Year 1 is : 1020
Your Total for Year 2 is : 1041

Sanfoundry Global Education & Learning Series – 1000 C# Programs.

If you wish to look at all C# Programming examples, go to 1000 C# Programs.

If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.