C Program to Calculate Simple Interest and Compound Interest

Program


#include<stdio.h>
#include<conio.h>
#include<math.h>

int main()
{
	 float p, t, r, si, ci;
	 clrscr();
	 printf("Enter principal amount (p): ");
	 scanf("%f", &p);
	 printf("Enter time in year (t): ");
	 scanf("%f", &t);
	 printf("Enter rate in percent (r): ");
	 scanf("%f", &r);
	
	 /* Calculating simple interest */
	 si = (p * t * r)/100.0;
	
	 /* Calculating compound interest */
	 ci = p * (pow(1+r/100, t) - 1);
	
	 printf("Simple Interest = %0.3f\n", si);
	 printf("Compound Interest = %0.3f", ci);
	 getch();
	 return(0);
}

Output of the above program :

Enter principal amount (p): 5000 ↲
Enter time in year (t): 2 ↲
Enter rate in percent (r): 18 ↲
Simple Interest = 1800.000
Compound Interest = 1962.000


Note: ↲ indicates ENTER is pressed.