Get free ebooK with 50 must do coding Question for Product Based Companies solved
Fill the details & get ebook over email
Thank You!
We have sent the Ebook on 50 Must Do Coding Questions for Product Based Companies Solved over your email. All the best!

Simple Interest Program in C

Last Updated on September 22, 2023 by Mayank Dham

Strings are the cornerstone of text manipulation and processing in Python. Whether you’re a beginner venturing into the world of programming or an experienced developer aiming to master the intricacies of string handling, a solid understanding of strings is essential. In this article, we embark on a journey to unravel the magic of string program in python, from basic operations to advanced techniques, equipping you with the tools to wield the power of text in your Python programs. A string in Python is denoted by single or double quotations. For example,

Simple Interest Formula

Simple Interest is a mathematical concept. It is a kind of interest in the capital that we get if we keep the money invested for a particular period of time. The formula for simple interest is:

Here, SI = Simple Interest
P = Principal amount
R = Rate of interest
T = Time period of investment

So, we will now implement this logic as a C program by writing the Simple interest program in C language.

Simple Interest Program in C – Logic Building

So, the aim is to calculate the simple interest. For calculating the simple interest, we need the Principal amount, Rate of Interest, and Time. So, we need to take these 3 quantities as input from the user. We will store them in 3 variables and then we will multiply them and divide the multiplication by 100 to get the simple interest.

However, if we store the Simple interest in an integer value and then divide by 100, only the integer part will be stored i.e. the floor value will be stored. So, we can use the float or double data types to store the decimal type of values. This will help us get the answer in decimals. So, the algorithm is as follows.

Algorithm to Find Simple Interest in C

  1. Input three integers and store them in three variables one by one. Let us say the variables are P, R, and T.
  2. Now, multiply the three variables i.e. PRT and divide this whole result by 100 and store it in a variable say SI.
  3. Print the resultant variable i.e SI. This will be the simple interest.

Simple Interest Program in C

# include <stdio.h>
# include <stdlib.h>

int main(){

    //Simple interset program
    int P, R, T;
    double SI;

    printf("Enter the principal: ");
    scanf("%d", &P);

    printf("Enter the rate: ");
    scanf("%d", &R);

    printf("Enter the time: ");
    scanf("%d", &T);

    SI = (P * R * T) / 100;
    printf("The Simple interest is %d", SI);

    return 0;

}

Time Complexity for Simple Interest Program in C:

The time complexity for simple interest program in C is O(1). This is because we are just performing 2 multiplications and 1 division i.e. constant operations. So, the time does not depend upon the size of the input.

Space Complexity for Simple Interest Program in C:

The space complexity of the simple interest program in C is also O(1). This is because we have not used any extra data structure. We have just created P, R, T, and SI variables that take up only constant space. So, the amount of space taken also does not depend upon the input size.

Simple Interest Program in C – Using a Function

The simple interest can also be calculated not inside the main function but rather, taking the input from the user in the main function and calculating the simple interest inside another function and calling that function from the main function. Making a separate function is always considered a better practice because it helps in providing code reusability. The following is the code for the same.

C Program for Simple Interest using Function

# include <stdio.h>
# include <stdlib.h>

double simple_interest(int P, int R, int T) {
    return (P*R*T)/100;
}

int main(){
    int P,R,T;
    printf("Enter the principal amount\n");
    scanf("%d",&P);
    printf("Enter the rate of interest\n");
    scanf("%d",&R);
    printf("Enter the time\n");
    scanf("%d",&T);
    
    double SI = simple_interest(P,R,T);
    printf("The Simple interest = %d",SI);
}

Time Complexity of Simple Interest Program in C using a Function:

Since there is no change in the logic of the code, the time complexity remains the same i.e. O(1). However, there will be an extra overhead of function calling this time.

Space Complexity of Simple Interest Program in C using a Function:

Since there is no change in the logic of the code, the space complexity of the program remains the same i.e. O(1). However, there will be a space overhead too for the function call as the function will acquire some memory in the function call stack.

So, this is the simple interest program in C. We hope that you have understood the concept and liked the discussion. We hope to see you again soon at PrepBytes.

Conclusion
The ability to calculate simple interest is a foundational skill that bridges programming and finance. Through the lens of C programming, we’ve delved into the heart of this computation, demystifying its mechanics and providing a hands-on example. This concept might be elementary, but its applications extend across various domains, from banking and finance to simulations and beyond. By grasping the fundamentals of calculating simple interest in C, you’re equipped to handle more complex financial computations and build a solid foundation for your programming journey.

FAQ related to simple interest program in c using function

Here are some FAQs related to simple interest program in c using function.

1. What is simple interest?
Simple interest is a method of calculating interest on an initial sum of money, known as the principal, at a fixed rate for a specified period.

2. What is the formula for calculating simple interest?
Simple Interest (SI) = (Principal Rate Time) / 100

3. How is simple interest different from compound interest?
Simple interest is calculated solely on the initial principal amount, while compound interest takes into account both the principal and the accumulated interest from previous periods.

4. What are the variables in the simple interest formula?
The variables are Principal (initial sum of money), Rate (interest rate per period), and Time (duration for which interest is calculated).

5. Can you provide an example of calculating simple interest in C?
Certainly! In the example section of this article, you’ll find a detailed C program that calculates simple interest step by step.

Other C Programs

C Program for Binary Search
C Program to Add Two Numbers
C Program to Calculate Percentage of 5 Subjects
C Program to Convert Binary Number to Decimal Number
C Program to Convert Celsius to Fahrenheit
C Program to Convert Infix to Postfix
C Program to Find Area of Circle
C Program to Find Roots of Quadratic Equation
C program to Reverse a Linked List
C program to reverse a number
Ascending Order Program in C
Menu Driven Program For All Operations On Doubly Linked List in C
C Program for Armstrong Number
C Program For Merge Sort For Linked Lists
C program for performing Bubble sort on Linked List
Hello World Program in C
Perfect Number Program in C
Leap Year Program in C
Odd Even Program in C
Selection Sort Program in C
Linear Search Program in C
While Loop Program in C
C Program to Swap Two Numbers
Calculator Program in C Language

Leave a Reply

Your email address will not be published. Required fields are marked *