**C TUTORIAL**

#

**C PROGRAMS**

C Basics

➤ Introduction to C

➤ Compile and Execute

➤ Hello, World! in C

➤ Identifiers & Keywords

➤ Data types in C

➤ Variables in C

➤ Comments in C

➤ Operators in C

➤ Bitwise Operators

➤ Printf() in C

➤ Input using scanf()

C Basic Programs

➤ Size & Range of Data Types

➤ C Programs for Beginners

➤ Add Subtract Multiply & divide

➤ Sum & Average of 3 Numbers

➤ Simple and Compound Interest

➤ Distance between two Points

➤ Find Circle Triangle Area

➤ ASCII Value of Character

➤ Find Square root of Number

➤ Different Swapping Programs

Here we will Write a Program to Compute Simple and Compound Interest in C. First, we will calculate the simple interest, and later we will calculate compound interest.

## C Program to Calculate Simple Interest

Program description:- Write a program to calculate simple interest by accepting the principle amount, time and rate values.

The simple interest is given by** ( principal amount * time * rate )/ 100**. We can take variables name as **p**, **t**, and **r** for the principal amount, time, and rate respectively for a better understanding purpose.

```
#include<stdio.h>
int main()
{
// declare variables
float p, t, r, interest;
// take inputs
printf("Enter principal amount(p),
time(t) and rate(r) values: ");
scanf("%f %f %f",&p,&t,&r);
// calculate simple interest
interest = ( p*t*r ) / 100;
// display result
printf("interest = %.2f\n",interest);
return 0;
}
```

Output:-

Enter principal amount(p), time(t) and rate(r) values: `5000 60 3.5`

Interest = 10500.00

## C Program to Calculate Compound Interest

Program description:- Write a program to find compound interest by accepting the principle amount, time and rate values.

Compound interest is calculated by multiplying the initial principal amount by one plus the annual interest rate raised to the number of compound periods minus one. After that, the total initial amount of the loan is then subtracted from the resulting value.

So, to calculate the annual compound interest, multiply the original amount of your investment or loan, or principal, by the annual interest rate. Add that amount to the principal, then multiply by the interest rate again to get the second year’s compounding interest.

For this purpose the* formula of compound interest*, including principal sum, is:` A = P*(1 + r/n)^(n*t)`

Where the meaning of these are:

A = the future value of the investment/loan, including interest

P = the principal investment amount (the initial deposit or loan amount)

r = the annual interest rate (decimal)

n = the number of times that interest is compounded per unit t

t = the time the money is invested or borrowed for

```
#include<stdio.h>
#include<math.h>
int main()
{
// declare variables
double princ, amount;
float rate, time;
int n;
// take inputs
printf("Enter principal amount: ");
scanf("%lf",&princ);
printf("Enter rate, time and number of times: ");
scanf("%f %f %d",&rate, &time, &n);
// calculate compound interest value
amount = princ*pow( (1+(rate/n)), (n*time));
// display result
printf("Amount=%.2lf",amount);
return 0;
}
```

Output:-

Enter principal amount: 5000

Enter rate, time and number of times: `0.05 10 12`

Amount=8235.10

If we are using Linux/Unix operating system and for this program getting an error “undefined reference to `pow'”. Then to solve this problem read:- *undefined reference to sqrt even math.h is included.*

If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or do you find anything incorrect? Let us know in the comments. Thank you!

Similar Basic C programming examples