Problem Statement: Write macro definitions with arguments for calculation of Simple Interest and Amount.
Store these macro definitions in a file called “interest.h”. Include this file in your program, and use the macro definitions for calculating simple interest and amount.
Output: Enter principal amount 1000 Enter Rate of Interest 9.2 Enter Time Period 2 Simple Interest: 184.00 Total Amount: 1184.00
In this program we take input for Principal amount, rate of interest and time period from the user, and then calculate Simple Interest for those values and also the total amount accumulated after getting simple interest.
Note: In Simple Interest formula we are dividing by 100.0 because the ( Principal_amount * Rate_of_interest * Time ) might yield a floating / double type value, so if we divide it by integer 100 then it might give wrong result.
We ask the user to enter values for floating point variables p, n, r and q. We use the formula:
a = p (1 + r / q) nq
And display the result to the console window.
where, p – principal amount; n – number of years. r – rate of interest; q – number of times interest compounds per year.
Note: We need to convert the user entered interest into percentage by dividing the integer number by 100.
Source Code: C Program To Calculate Amount In Compound Interest
#include<stdio.h>
#include<math.h>
int main()
{
float p, n, r, q, a;
int count;
for(count = 1; count <= 10; count++)
{
printf("Enter principal amount\n");
scanf("%f", &p);
printf("Enter number of years\n");
scanf("%f", &n);
printf("Enter rate of interest\n");
scanf("%f", &r);
r = r / 100;
printf("Enter no of times you compound per year\n");
scanf("%f", &q);
a = p * pow( (1 + (r/q)), n * q );
printf("Compounded amount is %f\n\n", a);
}
return 0;
}
Output Enter principal amount 5000 Enter number of years 2 Enter rate of interest 8 Enter no of times you compound per year 4 Compounded amount is 5858.296875
Enter principal amount 1000 Enter number of years 7 Enter rate of interest 5 Enter no of times you compound per year 1 Compounded amount is 1407.100464
Enter principal amount 2000 Enter number of years 5 Enter rate of interest 12 Enter no of times you compound per year 12 Compounded amount is 3633.393311
Enter principal amount 5000 Enter number of years 5 Enter rate of interest 5 Enter no of times you compound per year 5 Compounded amount is 6412.160156
Enter principal amount
Note: Above program keeps on iterating 10 times and asks the input 10 times.
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
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 );
Today lets learn some very important input types of HTML5:
datetime datetime-local date time week month
datetime input type is supported by Opera browser, but as of now(2013), Google Chrome doesn’t support it. All other input date time related input types are supported by Google Chrome.
Note: We can specify value, min, max and step attributes for all these input types. And the format for it is as shown below:
dateYYYY-MM-DD default step 60 seconds
timeHH:MM:SS.FF default step 1 Day (SS.FF means seconds and fractional seconds)
datetimeYYYY-MM-DDTHH:MM:SS.FFZ default step 60 seconds (T and Z means the TimeZone, these alphabets/characters must be literally present in the format)
datetime-localYYYY-MM-DDTHH:MM:SS.FF default step 60 seconds (albhabet/character/letter T must be literally present in the format)
weekYYYY-WNN default step of 1 week (letter W means the week, this alphabet/characters must be literally present in the format)
Twitter and other API’s return these kind of string Sun Mar 23 06:39:16 +0000 2008 which we store into a variable. using PHP standard function explode we separate the elements based on space.
Video Tutorial: Format Date and Insert Into Database Table: PHP