Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com

Calculate Simple Interest

Easy
0/40
308 upvotes

Problem statement

Take the principal amount, rate of interest, and the time period as input and calculate the Simple Interest.

Note: Return answer as Floor integer value.

Detailed explanation ( Input/output format, Notes, Images )
Input Format:
The first line of input contains a single integer Principal amount. 

The Second line of input contains a single decimal Rate of interest.

The Third line of input contains a single Integer Time period.
Output Format:
Calculate the Simple Interest and print it.
Sample Input 1:
2000
2.2
4
Sample Output 1:
176
Explanation of Sample Input 1:
The input is principal=2000, rate=2.2 and time=4.
So Simple interest=Principal*rate*time/100 hence 
answer is 2000*2.2*4/100=176
Approaches (1)
Using Simple Interest Formula

Take input of principal, rate and time respectively in three variables.

 

We can get the Simple interest by using the formula.

SI=(P* R * T)/100

 

Create a variable si and calculate it as above given formula and print it.
 

Time Complexity
Space Complexity
Code Solution
(100% EXP penalty)
Calculate Simple Interest
All tags
Sort by
Search icon

Interview problems

Code in c++

#include <bits/stdc++.h> 

 

#include <iostream>

 

using namespace std;  

 

int main() {

 

    float p,r,t,s;

 

    cin>>p;

 

    cin>>r;

 

    cin>>t;

 

    s=p*r*t/100;

 

    cout<<int(s);

 

    return 0;

 

}

11 views
0 replies
0 upvotes

Interview problems

JAVA code using "type Cast" operator

import java.util.* ;
import java.io.*; 
class Solution {
	
	public static void main(String args[]) {
		
		Scanner sc = new Scanner(System.in);

		int principal = sc.nextInt();
		float rate = sc.nextFloat();
		int time = sc.nextInt();

		int simpleIntrest = (int) (principal*rate*time)/100;

		System.out.println(simpleIntrest);
		
	}
}

 

 

IN LINE NO.16

int simpleIntrest = (int) (principle*rate*time)/100;

 

here (int) is a type cast operator which is used to perform narrowing . ie. narrowing is process of storing the larger type of data into smaller type.

 i.e. here float value of rate is converted into integer.

 

86 views
0 replies
0 upvotes

Interview problems

solustion

 solustion is 

 

   Scanner sc =new Scanner(System.in);

      int p=sc.nextInt();

     float s=sc.nextFloat();

     int ye=sc.nextInt();

     float an=p*s*ye/100;

     int ans=(int) an;

     System.out.println(ans);



using  JAVA 
35 views
0 replies
0 upvotes

Interview problems

CPP code (better than 100%)

#include <bits/stdc++.h> 

#include <iostream>

using namespace std;  

int main() {

    float p,r,t,s;

    cin>>p;

    cin>>r;

    cin>>t;

    s=p*r*t/100;

    cout<<int(s);

    return 0;

}

42 views
0 replies
0 upvotes

Interview problems

Best Working Solution

#include <bits/stdc++.h> 
#include <iostream>
using namespace std;

int main() {
    int principal, time, Simple_interest;
    float rate;
    cin>> principal >> rate >> time;
    Simple_interest = principal*rate*time/100;
    cout<< Simple_interest;

    return 0;
}
26 views
0 replies
1 upvote

Interview problems

Calculate Simple Interest

#include <bits/stdc++.h> 

#include <iostream>

using namespace std;

 

int main() {

    float p,r,t;

    cin>>p>>r>>t;

 

    float si = (p*r*t)/100;

    cout<<(int)si;

 

    return 0;

}

21 views
0 replies
0 upvotes

Interview problems

Calculate Simple Interest- C++

#include <bits/stdc++.h> 

#include <iostream>

using namespace std;

 

int main() {

    //Write your code here

    int P;

     cin>>P;

     float R;

     cin>>R;

     int T;

     cin>>T;

      int answer;

    answer=(P*R*T)/100;

    cout<<answer;

    return 0;

}

28 views
0 replies
1 upvote

Interview problems

Python Code

principal=int(input())

rate=float(input())

time=int(input())

 

si = int((principal*rate*time)/100)

print(si)

85 views
0 replies
0 upvotes

Interview problems

Calculate Simple Interest in java

import java.util.* ;

import java.io.*; 

class Solution {

    

    public static void main(String args[]) {

        

        // Write code here

        Scanner sc=new Scanner(System.in);

        int principal=sc.nextInt();

        float rate=sc.nextFloat();

        int time=sc.nextInt();

        int simple_interest=(int)((principal*rate*time)/100);

        System.out.println(simple_interest);

    }

}

156 views
0 replies
0 upvotes

Interview problems

JAVA SOUTION || Calculate Simple Interest ||

import java.util.* ;

import java.io.*; 

class Solution {

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);

        int principal = sc.nextInt();

        float rate = sc.nextFloat();

        int time = sc.nextInt();

        int SimpleInterest =(int) ((principal * rate * time) / 100);

        System.out.println(SimpleInterest);

    }

}

42 views
0 replies
0 upvotes
Full screen
Console