Last Updated : 18 Dec, 2024
Try it on GfG Practice
Given Principal p, Rate r and Time t, the task is to calculate Simple Interest.
Examples :
Input: p = 10000, r = 5, t = 5
Output:2500
Explanation: We need to find simple interest on Rs. 10,000 at the rate of 5% for 5 units of time.Input: p = 3000, r = 7, t = 1
Output:210
The basic idea is to calculate by applying the formula SI = (p x t x r)/100
C++
// CPP program to find simple interest for
// given principal amount, time and rate of interest
#include<iostream>
using namespace std;
float simpleInterest(float p, float t, float r){
/* Calculate simple interest */
float ans = (p * t * r) / 100;
return ans;
}
int main() {
float p = 1, r = 1, t = 1;
cout <<simpleInterest(p,r,t);
return 0;
}
C
#include <stdio.h>
float simpleInterest(float p, float t, float r) {
/* Calculate simple interest */
float ans = (p * t * r) / 100;
return ans;
}
int main() {
float p = 1, r = 1, t = 1;
printf("%f", simpleInterest(p, r, t));
return 0;
}
Java
class GfG {
static float simpleInterest(float p, float t, float r) {
/* Calculate simple interest */
return (p * t * r) / 100;
}
public static void main(String[] args) {
float p = 1, r = 1, t = 1;
System.out.println(simpleInterest(p, r, t));
}
}
Python
def simpleInterest(p, t, r):
/* Calculate simple interest */
return (p * t * r) / 100
if __name__ == "__main__":
p = 1
r = 1
t = 1
print(simpleInterest(p, r, t))
C#
using System;
class GfG {
public static float SimpleInterest(float p, float t, float r) {
/* Calculate simple interest */
return (p * t * r) / 100;
}
static void Main() {
float p = 1, r = 1, t = 1;
Console.WriteLine(SimpleInterest(p, r, t));
}
}
JavaScript
function simpleInterest(p, t, r) {
/* Calculate simple interest */
return (p * t * r) / 100;
}
//driver code
let p = 1, r = 1, t = 1;
console.log(simpleInterest(p, r, t));
Time complexity : O(1)
Auxiliary Space : O(1)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4