Program to Calculate Simple Interest [C, C++, Python & Java]

Posted in

Program to Calculate Simple Interest [C, C++, Python & Java]
vinaykhatri

Vinay Khatri
Last updated on November 23, 2024

    This tutorial helps you learn to write a program in C, C++, Python, and Java to calculate the simple interest when the user provides the principal amount, rate, and time.

    It is a straightforward program to implement. You must know the syntax of the programming language you use and the formula to calculate the simple interest.

    Before implementing a program, let us briefly understand the simple interest and its formula.

    What is Simple Interest?

    Simple interest is a concept having a real-world use case. It is a method of calculating an interest amount for a principal amount of money in a given time period.

    Here is the formula to calculate simple interest:

    SI = (p*r*t) / 100

    where SI = Simple interest, p = principal, r = rate, t = time in years

    C Program to Calculate Simple Interest

    #include<stdio.h>
    int main()
        {
           float SI, p,r,t;
           printf("Enter the principal amount: ");
           scanf("%f", &p);
    	   printf("Enter the rate of interest: ");
           scanf("%f", &r);
           printf("Enter the time period: ");
           scanf("%f", &t);
    	   SI = (p*r*t)/100;
    	   printf("The SI is: %f", SI);
    	   return 0;
    }

    Output

    Enter the principal amount: 45000
    Enter the rate of interest: 6
    Enter the time period: 7
    The SI is: 18900.000000

    C++ Program to Calculate Simple Interest

    #include<iostream>
    using namespace std;
    int main()
    {
       float SI, p,r,t;
       cout<<"Enter Principal: ";
       cin>>p;
       cout<<"Enter rate: ";
       cin>>r;
       cout<<"Enter Time: ";
       cin>>t;
       SI = (p*r*t)/100;
       cout<<"The SI is:"<<SI;
       return 0;
    }

    Output

    Enter Principal: 30000
    Enter rate: 2
    Enter Time: 4
    The SI is: 2400.0

    Python Program to Calculate Simple Interest

    p= float(input("Enter Principal: "))
    r= float(input("Enter rate: "))
    t= float(input("Enter Time: "))
    SI = (p*r*t)/100
    print("The SI is:",SI)

    Output

    Enter Principal: 30000
    Enter rate: 2
    Enter Time: 4
    The SI is: 2400.0

    Java Program to Calculate Simple Interest

    import java.util.*;
    public class Main
    {
        public static void main(String[] args)
        {
           float SI, p,r,t;
           Scanner sc = new Scanner(System.in);
           System.out.println("Enter the principal amount: ");
           p = sc.nextFloat();
    	   System.out.println("Enter the rate of interest: ");
           r = sc.nextFloat();
           System.out.println("Enter the time period: ");
           t = sc.nextFloat();
    	   SI = (p*r*t)/100;
    	   System.out.println("The SI is: " +SI);
    }
    }

    Output

    Enter the principal amount: 
    40000
    Enter the rate of interest: 
    5
    Enter the time period: 
    5
    The SI is: 10000.0

    Conclusion

    Well, you might have found the above program straightforward to understand. This basic program helps you understand how to take input from users and use it in your program to display the desired output. If you have any queries, comment below.

    People are also reading:

    Leave a Comment on this Post

    0 Comments