C Program for Simple and Compound Interest

C Program for Simple and Compound Interest
Bubble Sort and Binary Search: Click here
Selection Sort: Click Here
Write a C program to Calculate Simple Interest
#include<stdio.h>
main()
{
 float p,r,t,simpleInterest;
 printf(“Enter Principaln”);
 Scanf(“%f”, &p);
 printf(“ Enter Rate in percentage n”);
 scanf(“%f” ,&r);
 printf(“Enter Time in years(decimals)n”);
 scanf(“”%f” ,&t);
 simpleInterest=(float)(p*r*t)/100.0;
 printf(“Simple Interest is %fn”, simpleInterest);
}
Output
Enter Principal
2000
Enter Rate in percentage
5
Enter Time in years(decimals)
3
Simple Interest is 300.000000
Write a C program to Calculate Compound Interest
#include<stdio.h>
#include<math.h>
main()
{
//CI=P((1+r/n)^(nt))
float compoundInterest,principal,rate,time;
int n;
 printf(“Enter the principal valuen”);
 scanf(“%f” ,&principal);
 printf(“Ente rate in percentagen”);
 scanf(“%f” ,&rate);
 printf(“Enter time in years(decimals)n”);
 scanf(“%f” ,&time);
 printf(“Enter number of times interest is compounded per yearn”);
 scanf(“%d” ,&n);
compoundInterest=(float)(principal*pow(1+(rate/100*n))) , (n*time))));
printf(“CompoundInterest is %fn”,compoundInterest);
}
Output
Enter the principal value
5000
Enter rate in percentage
5
Enter time in years(decimals)
10
Enter number of times interest is compounded per year
12
Compound Interest 8235.047852

Leave a Comment