Computer Science, asked by RiyaVira13, 7 days ago

write a program to calculate compound interest​

Answers

Answered by anindyaadhikari13
18

\textsf{\large{\underline{Solution}:}}

The given problem is solved using language - Java.

import java.util.Scanner;

public class Brainly{

   public static void main(String s[]){

       Scanner sc=new Scanner(System.in);

       double p,r,t,a,ci;

       System.out.print("Enter Principal Amount: ");

       p=sc.nextDouble();

       System.out.print("Enter Rate Percentage (per annum): ");

       r=sc.nextDouble();

       System.out.print("Enter Time Period in years: ");

       t=sc.nextDouble();

       a=p*Math.pow(1+r/100.0,t);

       ci=a-p;

       ci=Math.round(ci*100)/100.0;

       System.out.println("The Compound Interest Earned: "+ci);

   }

}

\textsf{\large{\underline{Explanation}:}}

To calculate compound interest, we have to calculate the amount first. It is calculated by using the formula given below:

\sf\implies Amount=Principal\cdot\bigg(1+\dfrac{Rate}{100}\bigg)^{Time}

Now, Compound Interest is calculated using formula given below:

\sf\implies Compound\ Interest= Amount-Principal

Here, we have just taken the required values as input and using formula, compound interest is calculated.

Attachments:
Similar questions