Calculating simple interest is a basic financial calculation used to determine the interest earned or paid on a principal amount over a specific period. In this article, we'll learn how to write a C# program to calculate simple interest.
Problem Statement: Write a C# program to calculate the simple interest given the principal amount, rate, and time.
Example:
Suppose the principal amount is $1000, the interest rate is 5%, and the time is 3 years. The program should output:
Simple Interest: $150.00
Steps to Find Simple Interest.
C# Code to Find Simple Interest.
// C-sharp code implementation to calculate simple interest using System; namespace SimpleInterestCalculator { class Program { static void Main(string[] args) { Console.Write("Enter the principal amount: "); double principal = Convert.ToDouble(Console.ReadLine()); Console.Write("Enter the interest rate (in percentage): "); double rate = Convert.ToDouble(Console.ReadLine()); Console.Write("Enter the time (in years): "); double time = Convert.ToDouble(Console.ReadLine()); double simpleInterest = (principal * rate * time) / 100; Console.WriteLine($"Simple Interest: ${simpleInterest:F2}"); } } }
Enter the principal amount: 1000
Enter the interest rate (in percentage): 8
Enter the time (in years): 4
Simple Interest: $320.00
No comments:
Post a Comment