Hello Coders, in this article you will learn how to create an program in C language that calculates simple interest as per the input of the user. I have already uploaded the tutorial video of this program in my YouTube channel as well. If you want, you can also check that out. In order to create this program, as always we have to declare the header files at the top.
#include <stdio.h>#include <conio.h>{codeBox}
After finishing with the header files, we have to declare the main function with main() and then start writing the logic of the program. To achieve the objective, we declared some four floating value with float one for principal amount, one for the rate, one for the time and some for the simple interest. Then we asked for the input with the scanf function we asked for principal amount, rate and then time, and hence we calculated the simple interest with the general formula s = (p*t*r)/100. And finally we printed the output on the user screen with the printf function in C.
The whole program follows top-down approach. The full source code for this logic is given as below:
#include <stdio.h>#include <conio.h>main(){float p, t, r, s;printf("Enter Principal ");scanf("%f", &p);printf("Enter Time ");scanf("%f", &t);printf("Enter Rate ");scanf("%f", &r);s = (p * t * r) / 100;printf("The Simple Interest of Princiapl: Rs. %0.1f, Time: %0.1f years, Rate: %0.1f is Rs %0.2f", p, t, r, s);getch();}{codeBox}