C program to calculate Compound Interest
Here’s a C program that finds the size of int
, float
, double
, and char
:
#include
int main() {
printf("Size of int: %d bytes\n", sizeof(int));
printf("Size of float: %d bytes\n", sizeof(float));
printf("Size of double: %d bytes\n", sizeof(double));
printf("Size of char: %d bytes\n", sizeof(char));
return 0;
}
Output

Explanation:
- The program starts by including the
stdio.h
andmath.h
header files.stdio.h
is needed for input and output operations, whilemath.h
is needed for thepow
function used to calculate the exponentiation. - Inside the
main
function, we declare the variablesprincipal
,rate
,time
, andcompoundInterest
as doubles to store the respective values. - We then prompt the user to enter the principal amount, annual interest rate, and time in years using
printf
statements, and we read their input usingscanf
statements. - The compound interest is calculated using the formula:
compoundInterest = principal * pow((1 + rate/100), time)
. Thepow
function is used to calculate the exponentiation of(1 + rate/100)
to the power oftime
. - Finally, we use a
printf
statement to display the calculated compound interest with two decimal places.
When you run this program, it will prompt you to enter the principal amount, annual interest rate, and time in years. After you provide the inputs, it will calculate and display the compound interest.
- The program starts by including the