WAP that calculates the simple interest and compound interest. The principal amount, rate of interest and time are entered through the keyboard.
Here is your code :-
#include <stdio.h>
#include <math.h> // used for pow function used in compound_Interest formula.
int main()
{
// Initialisation of variables.
float simple_Interest, compound_Interest, principle, rate_of_interest, time;
printf("Enter the Principal amount, rate of Interest and time: ");
// Taking Input for principle amount, rate_of_interest and time.
scanf("%f%f%f", &principle, &rate_of_interest, &time);
// Using formula to find simple_Interest.
simple_Interest = (principle * rate_of_interest * time) / 100;
// Using formula to find compound_Interest.
compound_Interest = principle * pow((1 + rate_of_interest/100), time);
// printing the simple_Interest and compound_Interest found.
printf("The Simple Interest is : %f and compound interest is %f", simple_Interest, compound_Interest);
return 0;
}
Output:-
Explanation:-
Math.h library is used because we had used pow() function in Compound Interest Formula.
1. Intialisation of variables used.
2. Printing Statement of asking Input.
3. Taking Input of required Variables.
4.Used formula for both seperately.
5. Printing the results.
Comments
Post a Comment