Bank interest
Bank interest - C programming example
This program will provide us our bank statement where we will see our total amounts after every year.![]() |
| Bank interest |
C Programming Code
#include<stdio.h>
#include<conio.h>
#include<math.h>
main()
{
int n;
float p,r,i,a,b;
printf(" Enter the amount of money(in BDT): \n ");
scanf(" %f",&p);
printf(" Enter the rate of interest between 1-15: \n ");
scanf(" %f",&r);
if(r>=1 && r<=15){
printf(" Enter the time(in year): \n ");
scanf(" %d",&n);
i=p*r*n;
a=i/100;
b=p+a;
printf(" The principal with interest is %.2f. \n ",b);
}
else{
printf(" Please enter a valid rate of interest.\n ");
}
getch();
}
#include<conio.h>
#include<math.h>
main()
{
int n;
float p,r,i,a,b;
printf(" Enter the amount of money(in BDT): \n ");
scanf(" %f",&p);
printf(" Enter the rate of interest between 1-15: \n ");
scanf(" %f",&r);
if(r>=1 && r<=15){
printf(" Enter the time(in year): \n ");
scanf(" %d",&n);
i=p*r*n;
a=i/100;
b=p+a;
printf(" The principal with interest is %.2f. \n ",b);
}
else{
printf(" Please enter a valid rate of interest.\n ");
}
getch();
}
Output of the code
![]() |
| Bank Interest |
Explanation of the code
#include<stdio.h>
#include<conio.h>
Ø This
are called header file. A
header file is a file with extension .h which contains C function declarations
and macro definitions to be shared between several source files The C programming
language provides many standard library functions for file
input and output. These functions make up the bulk of
the C standard library header
<stdio.h>.In the other hand <conio.h> is a C header
file used mostly by MS-DOS compilers to provide console input/output. It is not
part of the C standard library or ISO C. This header declares several useful
library functions for performing "console input and output" from a
program.
·
main()
Ø In
C, program execution starts from the main() function. The main
function can in-turn call other functions. When main calls
a function, it passes the execution control to that function.
The function returns control to main when a
return statement is executed or when end of function is
reached.
·
int n
Ø int
is a variable or data type. A variable declared
to be of type int can be used for storing integer
numbers (values which doesn’t contain decimal places). Here we declare “n” as
int type. So this variables can take only integer values.
·
float p, r, i, a, b;
Ø float
is a variable or data type. A variable declared
to be of type float can be used for storing floating-point
numbers (values containing decimal places). Here we declare “p” , “r” , “i”
, “a” , and “b” variable in float type. So this three
variable can take values containing decimal number.
·
printf() function
Ø C
uses printf() function to write from the input devices. This function
has been declared in the header file called stdio.h
. Any text written within the pair of quotes ("") is displayed
as such by printf() function on the screen.
·
scanf() function
Ø This
function is used to get input from the user of the program. Here is 3 scanf
functions, scanf(“%f”,&p) is used here. So, this program will
read in a float value for “p” variable that the user enters on the
keyboard (%f is for float values. As there is “&p”, the
number user enters will be the value of “p” variable). scanf(“%f”,&r”) is used here. So, this program will read in a float value
for “n” variable that the user enters on the keyboard (%f is for
float values. As there is “&r”, the number user enters will be the
value of “r” variable).scanf(“%d”,&n”)
is used here. So,
this program will read in a integer value for “n” variable that the user
enters on the keyboard (%d is for integer values. As there is “&n”,
the number user enters will be the value of “n” variable).
·
if else loop
Ø If the expression evaluates to
true, then the if block will be executed,
otherwise, the else block will be executed. Here, we can see
that in the brackets of if loop,
there is a expression “r>=1 && r<=15” .If the entered value
of r is greater than or equals to 1 and less than or equals to 15, the code
within if block will be executed. If
not so, then the code within else block
will be executed.
·
getch() function
getch() is used to hold
the console(output) window on the screen after the whole program run is
completed till the user enters a key from keyboard. This function is present in
the header file called conio.h.
Now lets see this code in a flowchart
Flowchart of the code
|
If we enter the principal, the rate of interest and
the year, this program will tell us the principal of interest.


No comments