Problem 03

author
By Supreme2023-02-14
Problem Statement :
Write a program to calculate simple interest (i = (p*r*n)/100 ) i = Simple interest p = Principal amount r = Rate of interest n = Number of years
Code:

#include <stdio.h>

int main()
{
// 3. Write a program to calculate simple interest (i = (p*r*n)/100 )
// i = Simple interest
// p = Principal amount
// r = Rate of interest
// n = Number of years

float i, p, r, n;

printf("\tSimple Intrest Calculator");
printf("\n======================================");

printf("\n\nEnter The Principal Amount : ");
scanf("%f", &p);

printf("\nEnter Rate Of Intrest : ");
scanf("%f", &r);

printf("\nEnter Number of years : ");
scanf("%f", &n);

printf("\n______________________________________");

i = (p * r * n) / 100;

printf("\n\nFinal Intrest will be : %.2f Rs.", i);
printf("\n\nFormula Used (i = (p*r*n)/100)");
printf("\n______________________________________\n\n");

return 0;
}

Description :
  • This program calculates the simple interest on a principal amount based on the user's input of the principal amount, rate of interest, and the number of years. It uses the formula i = (p * r * n) / 100 to calculate the simple interest, where i is the simple interest, p is the principal amount, r is the rate of interest, and n is the number of years.
  • The program starts by declaring four floating-point variables i, p, r, and n to store the simple interest, principal amount, rate of interest, and number of years, respectively.
  • The program then prompts the user to enter the principal amount, rate of interest, and the number of years, which are read in using scanf() and stored in the variables p, r, and n, respectively.
  • The simple interest is then calculated using the formula i = (p * r * n) / 100, and stored in the variable i.
  • Finally, the program displays the calculated simple interest along with the formula used to calculate it. The statement return 0; at the end of main() indicates that the program has executed successfully and returns an exit code of 0.
Output Image:
Output-image

© Copyright 2022. All right reserved, GTU Coder.