Program to calculate simple interest in C
/*calculation of simple interest*/ #include<stdio.h> /*#include is a preprocessor directive and #include<stdio.h> is a declaration for printf() function*/ int main() /*main() is a function or a cointainer for a set of statements*/ { int p,n; /*declaration*/ float r,si; /*declaration*/ p=50000; //p=principal n=10; //n=number of years r=2500; //r=rate si=p*n*r/100; //using formula for simple interest printf("%f\n",si); /*printf() displays output on the screen, %f is used to print real value, and \n takes cursor to next line*/ return 0; /*as we are using int before main(), it return a value 0*/ } In the above program, Every time we run the program we would get the same output but if you want to supply the values of p, r, and n through the keyboard during the execution, you need to use a function scanf( ). /*calculation of simple interest, taking values from user*/ #include<s