#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;
}
Problem of the day
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.
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.
2000
2.2
4
176
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
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.
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;
}
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.
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 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;
}
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;
}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;
}
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;
}
Interview problems
Python Code
principal=int(input())
rate=float(input())
time=int(input())
si = int((principal*rate*time)/100)
print(si)
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);
}
}
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);
}
}