In this example, We will calculate Compound Interest. For calculating compound interest formula given below
Program to calculate compound interest in c
#include<stdio.h>
#include<math.h>
void main()
{
int p,t;
float r,ci;
printf("Enter Principal Amount");
scanf("%d",&p);
printf("Enter Rate of Interest");
scanf("%f",&r);
printf("Enter time in years");
scanf("%d",&t);
ci = p * pow((1+r/100),t);
printf("Compound Interest = %.2f",ci);
}
Output
Enter Principal Amount
1000
Enter Rate of Interest
5
Enter time in years
2
Compound Interest = 1102.50
Explanation
In this program we have used a new header file math.h Because we used a pow() function which is written in math.h header file.
Introduction of C and Hello World Program
C program to Addition of two numbers
C program to find Area of Triangle
C program to find Area of Circle
C program to find Area of Rectangle
C program to Calculate Simple Interest