Write a Program to Find Simple Interest and Compound Interest.

Table of Contents
< All Topics
Print

Write a Program to Find Simple Interest and Compound Interest.

Aim

This type of expression-based programs are supposed to be basic c-program, where user gives some inputs like for principal amount as p, time as n years and rate of interest as r. Finally, using the mathematical formula as expression will help in writing a C program to find the Simple Interest and Compound Interest.

Procedure/ Algorithm

Step-1: Start the program execution.

Step-2: Declare the variables p, n, r.

Step-3: Input the values for p, n, r.

Step-4: Calculate and print the values of simple interest.

OR

Step-5: Calculate and print the values of compound interest.

Step-6: Stop the program execution.

Hello WorldBlockHello World

// Program to calculate simple interest
#include<stdio.h>
#include<math.h>
int main()
{
int p,n;
float r;

printf("\nEnter the value of amount, number of years and Rate of interest:");
scanf("%d%d%f",&p,&n,&r);

float SI=(p*n*r)/100);

printf("\nThe simple interest is = %f",SI));

return 0;
} // end main

Output


Enter the value of amount, number of years and Rate of interest:
100
5
4

 The simple interest is = 20.000000

--------------------------------
Process exited after 8.76 seconds with return value 0
Press any key to continue . . .

Program: Calculate the Compound Interest

// Program to calculate compound interest
#include<stdio.h>
#include<math.h>
int main()
{
int p,n;
float r;

printf("\nEnter the value of amount, number of years and Rate of interest:");
scanf("%d%d%f",&p,&n,&r);

float CI=p*pow((1+(r/100)),n)-p;

printf("\nThe compound interest is = %f",CI);

return 0;
} // end main

Output


Enter the value of amount, number of years and Rate of interest:
100
5
4

The compound interest is = 21.665268
--------------------------------
Process exited after 8.76 seconds with return value 0
Press any key to continue . . .

Run Directly on in-built C-Compiler

Result

Thus, the C program has been written, executed successfully to calculate the simple interest and compound interest.


Recommended Readings

Leave a comment