For working professionals
For fresh graduates
More
5. Array in C
13. Boolean in C
18. Operators in C
33. Comments in C
38. Constants in C
41. Data Types in C
49. Double In C
58. For Loop in C
60. Functions in C
70. Identifiers in C
81. Linked list in C
83. Macros in C
86. Nested Loop in C
97. Pseudo-Code In C
100. Recursion in C
103. Square Root in C
104. Stack in C
106. Static function in C
107. Stdio.h in C
108. Storage Classes in C
109. strcat() in C
110. Strcmp in C
111. Strcpy in C
114. String Length in C
115. String Pointer in C
116. strlen() in C
117. Structures in C
119. Switch Case in C
120. C Ternary Operator
121. Tokens in C
125. Type Casting in C
126. Types of Error in C
127. Unary Operator in C
128. Use of C Language
Calculating interest is a basic but important concept in finance and programming. In this guide, we will focus on creating a simple interest program in C. You will learn how to write clean and efficient C code to calculate simple interest using different approaches like direct calculation and functions. Whether you are a beginner or revising your basics, this article will help you understand the concept and coding practice step-by-step.
In this article, we will first explain what simple interest is and discuss the formula used to calculate it. After that, we will walk through the logic behind the simple interest program in C language. You will also see different implementations, including programs using float data types and functions, along with a final conclusion to summarize the learning.
Explore Online Software Engineering Courses from top universities.
The interest amount for a loan or principal amount is known as simple interest. This term is used in various sectors such as banking, automobile, finance, etc. Suppose a person borrows some money from the bank for a specific time period. Here the borrowed money is called the principal amount. While paying back the person must give some extra money apart from the principal amount. This extra money is called simple interest which depends upon the principal amount and the time period. Simple interest is basically the borrowing cost. Here a brief idea about simple interest, its definition, formula to calculate simple interest are represented.
Be future-ready with following AI-powered courses, and build an exceptional high-paying career:
If the principal amount, rate of interest, and time periods are given then the simple interest is calculated as:
Simple Interest (SI) = PTR /100
Here,
P = Principal amount
T = Time period (in years) for which the money is borrowed
R = Rate of Interest in percentage
Example:
A person borrows Rs 20000 from the bank for a time period of 1 year. The rate of interest is 20% per annum. Find a simple interest.
Solution:
Here, the principal amount = P = Rs 20000
The time period for which the money is borrowed = T = 1 year
The rate of interest per annum = R =20%
Then simple interest for a year = SI = PTR/100
SI = Rs 4000
The person has to pay an extra amount of Rs 4000 along with the principal amount to the bank at the end of one year.
A simple interest program in C programming is written and explained in the next paragraph.
Here the goal is to calculate simple interest value. So, three types of information are required from the user such as the principal amount, the time period for which the money is borrowed, and the rate of interest per annum. These three values are given as input to the computer and simple interest is the output value. The input values are stored in three variables. Then the formula is applied where the three input variables are multiplied and then divided by 100 to get the required output value i.e. simple interest.
Must Explore: Pattern Program in C: A Complete Guide article!
The algorithm used to compute simple interest in C language is presented here.
Check out the Mastering Palindrome Program in C: Techniques and Code Examples article!
Calculating simple interest with integers is the simplest method. This approach uses whole numbers for principal, time, and rate.
#include <stdio.h>
int main() {
int principal, time, rate, simpleInterest;
// Taking Principal amount as input
printf("Enter Principal amount: ");
scanf("%d", &principal);
// Taking Time duration in years
printf("Enter Time (in years): ");
scanf("%d", &time);
// Taking Rate of interest
printf("Enter Rate of Interest: ");
scanf("%d", &rate);
// Calculating Simple Interest using the formula
simpleInterest = (principal * time * rate) / 100;
// Displaying the result
printf("Simple Interest = %d\n", simpleInterest);
return 0;
}
Sample Output:
Enter Principal amount: 1000
Enter Time (in years): 2
Enter Rate of Interest: 5
Simple Interest = 100
Explanation:
User enters principal as 1000, time as 2 years, and rate as 5%.
Formula used: (Principal × Time × Rate) / 100
Calculation: (1000 × 2 × 5) / 100 = 100
Final simple interest is displayed as 100.
Also check out the C Hello World Program: A Beginner’s First Step in C Programming!
Sometimes we deal with decimal values for money and rate. In such cases, we use float for better accuracy.
#include <stdio.h>
int main() {
float principal, time, rate, simpleInterest;
// Taking Principal amount as input
printf("Enter Principal amount: ");
scanf("%f", &principal);
// Taking Time duration in years
printf("Enter Time (in years): ");
scanf("%f", &time);
// Taking Rate of interest
printf("Enter Rate of Interest: ");
scanf("%f", &rate);
// Calculating Simple Interest using the formula
simpleInterest = (principal * time * rate) / 100;
// Displaying the result
printf("Simple Interest = %.2f\n", simpleInterest);
return 0;
}
Sample Output:
Enter Principal amount: 1200.50
Enter Time (in years): 3.5
Enter Rate of Interest: 4.5
Simple Interest = 189.08
Explanation:
User enters principal as 1200.50, time as 3.5 years, and rate as 4.5%.
Formula used: (Principal × Time × Rate) / 100
Calculation: (1200.50 × 3.5 × 4.5) / 100 ≈ 189.08
Output shows Simple Interest up to two decimal places
Using functions makes the code modular, easier to debug, and reusable.
#include <stdio.h>
// Function to calculate Simple Interest
float calculateSimpleInterest(float principal, float time, float rate) {
return (principal * time * rate) / 100; // Returning the calculated interest
}
int main() {
float principal, time, rate, simpleInterest;
// Taking Principal amount as input
printf("Enter Principal amount: ");
scanf("%f", &principal);
// Taking Time duration in years
printf("Enter Time (in years): ");
scanf("%f", &time);
// Taking Rate of interest
printf("Enter Rate of Interest: ");
scanf("%f", &rate);
// Calling function to calculate Simple Interest
simpleInterest = calculateSimpleInterest(principal, time, rate);
// Displaying the result
printf("Simple Interest = %.2f\n", simpleInterest);
return 0;
}
Sample Output:
Enter Principal amount: 5000
Enter Time (in years): 5
Enter Rate of Interest: 6
Simple Interest = 1500.00
Explanation:
Principal = 5000, Time = 5 years, Rate = 6%.
calculateSimpleInterest function is called with these inputs.
Calculation: (5000 × 5 × 6) / 100 = 1500.
Program outputs the calculated simple interest: 1500.00.
You can define a macro for the simple interest formula to reduce repetition.
// Using macro to calculate Simple Interest
simpleInterest = SIMPLE_INTEREST(principal, time, rate);
printf("Simple Interest = %.2f\n", simpleInterest);
return 0;
}
Sample Output:
Enter Principal amount: 1000
Enter Time (in years): 2
Enter Rate of Interest: 5
Simple Interest = 100.00
Explanation:
Macro SIMPLE_INTEREST(p, t, r) directly replaces the formula.
No need for an extra function call.
Faster and very clean for small formulas.
You can pass the principal, time, and rate values directly through the terminal using command-line arguments.
#include <stdio.h>
#include <stdlib.h> // Required for atof()
int main(int argc, char *argv[]) {
if (argc != 4) {
printf("Usage: %s principal time rate\n", argv[0]);
return 1;
}
// Converting command-line arguments to float
float principal = atof(argv[1]);
float time = atof(argv[2]);
float rate = atof(argv[3]);
float simpleInterest = (principal * time * rate) / 100;
printf("Simple Interest = %.2f\n", simpleInterest);
return 0;
}
Output (Example Terminal Imput):
$ ./a.out 1500 2 7
Simple Interest = 210.00
Explanation:
User passes values while running the program.
Saves the need for scanf() inputs.
Useful for automation or quick batch calculations.
Also explore the Anagram Program in C tutorial!
A clear assessment regarding the calculation of simple interest using C programming is explained here. The simple interest formula is defined and how to calculate it in the C programming environment is shown.
What is C programming?
C is a modern programming language that includes a rich set of built-in functions, data types, and operators.
How to calculate simple interest?
If the principal amount, rate of interest, and time periods are given then the simple interest is calculated as
Simple Interest (SI) = PTR /100
P = Principal amount
T = Time period (in years) for which the money is borrowed
R = Rate of Interest in percentage
What is stdio.h?
Here stdio.h means single input single output. This is a built-in header file in the C programming language. It contains the information related to the input and output functions.
What is int main ()?
int main() function is used as the starting point of program execution. It directs the calls to other functions in the program and thus controls program execution
What is printf?
printf is an output function that indicates “print formatted”.
What is scanf?
Scanf is an input function that is used to read input from the user.
What is the meaning of int and float in C programming?
“int” keyword stands for integer data type and it is used to declare integer value. The format specifier “%d” is used to display an integer value. float is a datatype used to store floating point numbers. Floating point numbers mean numbers with a decimal point. Format specifier %f is used to declare the floating numbers.
What is the use of function in C programming?A function is defined as a block of codes and it runs whenever it is called. The set of statements inside the curly bracket is used for the computation part by taking input arguments. The function can be called multiple times.
What are the applications of the Simple Interest Program in C?
The simple interest program in C helps calculate interest on loans, savings accounts, and bonds. It is commonly used in banking software, financial calculators, and education-based C programming projects.
Why do we prefer using float variables in the Simple Interest Program in C?
We use float variables to handle decimal values accurately in the simple interest program in C. This ensures precise calculation when the principal amount, rate, or time period contains fractional values.
Can we calculate compound interest using the same logic as simple interest?No, compound interest involves calculating interest on both the principal and accumulated interest. Simple interest is calculated only on the principal, so the logic for compound interest differs.
Take a Free C Programming Quiz
Answer quick questions and assess your C programming knowledge
Author|900 articles published
Previous
Next
Start Learning For Free
Explore Our Free Software Tutorials and Elevate your Career.
Talk to our experts. We are available 7 days a week, 9 AM to 12 AM (midnight)
Indian Nationals
1800 210 2020
Foreign Nationals
+918068792934
1.The above statistics depend on various factors and individual results may vary. Past performance is no guarantee of future results.
2.The student assumes full responsibility for all expenses associated with visas, travel, & related costs. upGrad does not provide any a.