GoogleTag

Google Search

[Programming] Question 15: Write a C program to calculate Compound Interest

Learn how to write a C program to calculate compound interest. This guide explains how to implement the formula for compound interest, which includes principal amount, interest rate, number of times interest is compounded per year, and the total number of years. The tutorial includes sample code, explanations of the formula used, and tips for accurate calculations.

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

int main() {
	float principal, rate, time, compoundInterest;

	printf("Enter principal amount: ");
	scanf("%f", &principal);

	printf("Enter rate of interest: ");
	scanf("%f", &rate);

	printf("Enter time in years: ");
	scanf("%f", &time);

	compoundInterest = principal * (pow((1 + rate / 100), time)) - principal;

	printf("Compound Interest = %.2f\n", compoundInterest);

	return 0;
} 

Inside the main() function:

- Float variables principal, rate, time, and compoundInterest are declared to store principal amount, rate of interest, time, and compound interest respectively.

- The user is prompted to enter the principal amount, rate of interest, and time.

- Compound interest is calculated using the formula: CI = P * (1 + R/100)^T - P.

- The calculated compound interest is printed to the console.



Featured Posts

SQL Interview Questions Topics

 SQL Topics to prepare for interviews,   SQL Basics: Introduction to SQL SQL Data Types DDL (Data Definition Language): C...

Popular Posts