Simple Interest: C Program

Advertisement:

Video Tutorial illustrating: C Program To Calculation of Simple Interest.

Header File:

   #include<stdio.h>

To be able to use printf function, we have to include stdio.h header file.

main()
This is the starting point of C program execution.
since it does not return any value, we write void main()

Declaration of Variables:

   	int p, n;
	float r, si;

variables p and n are integer type variables i.e., they can hold integer values.
variables r and si are float or real type variables i.e., they can hold fractional values.

   clrscr();

to clear the output screen.

Initialization of Variables:

   	p = 1000;
	n = 3;
	r = 8.5;

Principle p = 1000
n or time or duration = 3
rate of interest r = 8.5

Formula to calculate simple interest:

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

The mathematical formula si = ( p x n x r ) / 100; is written as si = ( p * n * r ) / 100;

Output statement:

	printf("%f\n",si);

the function printf is present inside stdio.h header file. %f is formatting string for float or real type values.

	getch();

function to return to the console window.

Video Tutorial: C Program to calculate Simple Interest


You need to a flashplayer enabled browser to view this YouTube video

YouTube Link: http://www.youtube.com/watch?v=TGgd6KvL_W0 [Watch the Video In Full Screen.]



Full Source code to calculate simple interest in C program:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include<stdio.h>
 
void main()
{
 
	int p, n;
	float r, si;
 
	clrscr();
 
	p = 1000;
	n = 3;
	r = 8.5;
 
	si = ( p * n * r ) / 100;
 
	printf("%f\n",si);
 
	getch();
}

Output:
255.000000

Advertisement:

Enter your email address:

RSS Feed




Leave a Reply