C Program to Calculate Simple Interest and Compound Interest

This C program calculates simple and compound interest given principal amount, rate and time by user.

Following formula are used in this program to calculate simple and compound interest in this C program:

Simple Interest = (P*T*R)/100

Compound Interest = P * ( (1+r/100 )t - 1)

C Source Code: Simple & Compound Interest


#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);
}

C Output: Simple & Compound Interest

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.