C Program to Calculate the Compound Interest

In this video tutorial lets learn how we can calculate Compound Interest by making use of simple arithmetic operations.

 
#include < stdio.h >
#include < math.h >

int main()
{
    int p, t;
    float r, ci;

    printf("Enter principal amount\n");
    scanf("%d", &p);

    printf("Enter rate of interest\n");
    scanf("%f", &r);

    printf("Enter time period\n");
    scanf("%d", &t);


    ci = p * pow( (1 + r / 100), t );

    printf("Compound Interest is %f\n", ci);

    return 0;
}

Output:
Enter principal amount
1000
Enter rate of interest
8.5
Enter time period
3
Compound Interest is 1277.289185

Note: Since we’re using pow() method, we need to include math.h library file.

Scanf(): For user input

In above c program we are asking user to enter the values for variable a and b. You can know more about scanf() method/function in this video tutorial: Using Scanf in C Program

C Program to Calculate the Compound Interest


[youtube https://www.youtube.com/watch?v=DsRImGajlHw]

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


In this program we take input for Principal amount, rate of interest and time period from the user, and then calculate Compound Interest for those values.

Compound Interest Logic




We make use of arithmetic operations available in C programming language and convert this formula to calculate Compound Interest.

Compound_Interest = Principal_amount * pow( (1 + r / 100), t );

This gives us Compound Interest and we output the result to the console.

Formula for calculating Compound Interest

p – Principal amount.
r – Rate of interest.
t – Time period.
ci – Compound Interest.

Yearly Compound Interest Formula
Compound_Interest = Principal_amount * pow( (1 + r / 100), t );

Half-Yearly Compound Interest Formula
Compound_Interest = Principal_amount * pow( (1 + (r/2) / 100), 2 * t );

Quarterly Compound Interest Formula
Compound_Interest = Principal_amount * pow( (1 + (r/4) / 100), 4 * t );

Monthly Compound Interest Formula
Compound_Interest = Principal_amount * pow( (1 + (r/12) / 100), 12 * t );

For full C programming language free video tutorial list visit:C Programming: Beginner To Advance To Expert

Draw Arcs/Circle with Canvas: HTML5

Today lets learn how to use arcs and paths to draw circle.

Arcs are curves that are portions of a circle. A full circle is a 360 degree arc!
A Path is a collection of some lines(or shapes) that once defined can be either filled or stroked.

index.html and myStyle.css files are kept same as illustrated in previous video tutorial: Canvas State: HTML5

Syntax
arc(x, y, r, sA, eA, TF);

arc method takes 6 parameters. x and y are the x-axis and y-axis, which is the center of the circle.
i.e., The x and y parameters determine where the center of the circle will be located on your canvas.

r is the radius of the circle, in pixels.
i.e., the distance of the curve from the center of the circle.

sA is start angle of the circle.
eA is the end angle of the circle.

TF is the direction – which can take 2 values i.e., True or False.

True: negative degrees, counter-clockwise direction.
False: positive degrees, clockwise direction.

Javascript file
myScript.js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
window.onload = canvas;
 
function canvas()
{
var myCanvas = document.getElementById("myCanvas");
 
if( myCanvas && myCanvas.getContext("2d") ) 
{
var context         = myCanvas.getContext("2d");
 
context.lineWidth= 6;
context.beginPath();
 
var degree = 270;
var radian = ( Math.PI / 180 ) * degree;
 
context.arc(100, 100, 50, 0, radian, false);
context.strokeStyle= "red";
context.fillStyle= "blue";
context.stroke();
context.fill();
context.closePath();
 
}
}

Degree to Radian

radians-and-degrees

We convert degrees to radians using a simple mathematical formula:
Radians = (PI / 180 ) * degree;

Draw Arcs/Circle with Canvas: HTML5


[youtube https://www.youtube.com/watch?v=vE0bstctkp4]

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



Note:
1. By default, direction of drawing the arc is clockwise/positive degrees(i.e., the value of last parameter is false).
2. PI value is 180.
3. 2 * PI is 360!
4. arc method should be passed with radian values and not degrees.