Simple Interest Program in C
“Simple interest is essentially a calculation of the interest a bank will charge a customer or itself on a certain principal amount over a specific period of time.”
The formula for calculating the Simple Interest is given by
Simple Interest=(P*T*R)/100
Where,
- P is known as the principal amount.
- T is known as the time period.
- R is known as the rate of interest for the respective amount and the time Period.
There are different techniques used for implementation of the Simple Interest in C programming. They are as follows.
- General method using main() only.
- Using for Loop.
- Using while Loop.
- Using do-while Loop.
- Using Functions.
- Using Pointers.
Simple Interest implementation in C Using main() Method
// A Simple Interest Programme Using Given Values// A Simple Interest Programme Using Given Values in C #include <stdio.h> int main() { float P,T,R,Simple_Interest; // `P` = Principal, `T` = Time period, and `R` = Rate of Interest // `Simple_Interest` = Value of Interest printf("Enter the Principal amount : "); scanf("%f",&P); printf("Enter the Time period: "); scanf("%f",&T); printf("Enter the rate of Interest: "); scanf("%f",&R); // It will determine the simple interest Simple_Interest = (P* T * R) / 100; // Final output is obtained printf("\nSimple_Interest = %.2f\n", Simple_Interest); return 0; }
OUTPUT:
Simple Interest implementation in C Using For Loop Method:
// A simple interest programme in C that makes use of a for loop #include <stdio.h> int main() { float a = 1, b, Simple_Interest; // `Simple_Interest` = Value of Interest printf("Enter the Principal,Time Period, and Rate of Interest::\n"); for (int count = 1; count <= 3; count++) { scanf("%f", &b); // It will determines the simple Interest a *= b; if (count == 3) Simple_Interest = a/100; } // Final Output is obtained printf("\nSimple_Interest = %.2f\n", Simple_Interest); return 0; }
OUTPUT:
Simple Interest implementation in C Using While Loop Method:
// A simple interest programme in C that makes use of a While loop #include <stdio.h> int main() { float a = 1, b, Simple_Interest; // `Simple_Interest` = Value of interest printf("Enter the Principal , Time period, and Rate of Interest ::\n"); int count = 1; while (count <= 3) { scanf("%f", b); // It will determines the simple interst a *= b; if (count == 3) Simple_Interest = a/100; count++; } // final output is obtained printf("\nSimple_Interest = %.2f\n", Simple_Interest); return 0; }
OUTPUT:
Simple Interest implementation in C Using do-While Loop Method:
// A simple interest programme in C that makes use of a do-While loop #include <stdio.h> int main() { float a = 1, b, Simple_Interest; // `Simple_Interest` = Value of Interest printf("Enter the Principal, Time Period, and Rate of Interest::\n"); int count = 1; do { scanf("%f", &b); // It will determine the Simple Interest a *= b; if (count == 3) Simple_Interest = a/100; count++; } while (count <= 3); //Final output is obtained printf("\nSimple Interest = %.2f\n", Simple_Interest); return 0; }
OUTPUT:
Simple Interest implementation in C Using Functions Method:
// A simple interest programme in C that makes use of a Functions #include <stdio.h> // This function will determine the value of simple interest void SimpleInterest(float a, float b, float c) { float Simple_Interest; // Value of Interest // It will determine the Simple Interest Simple_Interest = (a * b * c) / 100; // final output is obtained printf("\nSimple Interest = %.2f\n", Simple_Interest); } // Driver Function int main() { float P, T, R; // `P` = Principal, `T` = Time period, and `R` = Rate of Interest printf("Enter the Principal, Time Period, and Rate of Interest::\n"); scanf("%f%f%f", &P, &T, &R); SimpleInterest(P, T, R); return 0; }
OUTPUT:
Simple Interest implementation in C Using Pointers Method:
// A simple interest programme in C that makes use of a Pointers #include <stdio.h> int main() { float P, T, R, Simple_Interest; // `P` = Principal, `T` = Time Period, and `R` = Rate of Interest // `Simple_Interest` = Value of simple Interest float *a, *b, *c; // Declartion of the pointer variables printf("Enter the Principal, Time Period, and Rate of Interest::\n"); scanf("%f%f%f", &P, &T, &R); a = &P; b = &T; c = &R; // It will determine the Simple Interest Simple_Interest = (*a * *b * *c) / 100; // final output is obtained printf("\nSimple_Interest = %.2f\n", Simple_Interest); return 0; }
OUTPUT: