Example of C part 45 calculate compound interest
Program :
Output:
Enter Principal
5000
Enter rate in percentage
5
Enter time in years(demcimals)
10
Enter number of times interest is compounded per year
12
Compound Interest is 8235.047852Explanation:
Formula for CI:
#include<stdio.h> #include<math.h> main() { //CI=P((1+r/n)^(nt)) float compoundInterest,principal,rate,time; int n; printf("Enter Principal\n"); scanf("%f",&principal); printf("Enter rate in percentage\n"); scanf("%f",&rate); printf("Enter time in years(demcimals)\n"); scanf("%f",&time); printf("Enter number of times interest is compounded per year\n"); scanf("%d",&n); compoundInterest=(float)(principal*(pow((1+(rate/(100*n))),(n*time)))); printf("Compound Interest is %f\n",compoundInterest); }
Enter Principal
5000
Enter rate in percentage
5
Enter time in years(demcimals)
10
Enter number of times interest is compounded per year
12
Compound Interest is 8235.047852Explanation:
Formula for CI:
CI=Principal((1+rate/n)^(n*time))
- We used
- principal → To store principal in Rupees
- rate → To store rate in %
- time → To store time in years
- n →To store number of times interest is compounded per year
- compoundInterest → To store output
printf("Enter Principal\n"); scanf("%f",&principal); printf("Enter rate in percentage\n"); scanf("%f",&rate); printf("Enter time in years(demcimals)\n"); scanf("%f",&time); printf("Enter number of times interest is compounded per year\n"); scanf("%d",&n);
Taking all the required variables as input from usercompoundInterest=(float)(principal*(pow((1+(rate/(100*n))),(n*time)))); printf("Compound Interest is %f\n",compoundInterest);
compoundInterest is calculated by using formula and is then printed.