Calculate simple interest

Here given code implementation process.

//C Program 
//Calculate simple interest
#include <stdio.h>

//Method which is take three parameters
//And calculates that simple interest
//Here time is form in year
//rate is form of annual interest rate
void simple_interest(double principle, double time, double rate)
{
	//Display parameters values
	printf("Principle : %lf\n", principle);
	printf("Time : %lf\n", time);
	printf("Rate : %lf\n", rate);
	//Calculate interest
	double amount = (principle * time * rate) / 100;
	//Display amount
	printf("Simple Interest : %lf\n\n", amount);
}
int main()
{
	//Test Cases
	simple_interest(1500, 3, 7.3);
	simple_interest(170.4, 7, 3.4);
	return 0;
}

Output

Principle : 1500.000000
Time : 3.000000
Rate : 7.300000
Simple Interest : 328.500000

Principle : 170.400000
Time : 7.000000
Rate : 3.400000
Simple Interest : 40.555200
/*
  Java Program
  Calculate simple interest
*/
class MyMaths
{
	//Method which is take three parameters
	//And calculates that simple interest
	//Here time is form in year
	//rate is form of annual interest rate
	public void simple_interest(double principle, double time, double rate)
	{
		//Display parameters values
		System.out.print("Principle : " + principle + "\n");
		System.out.print("Time : " + time + "\n");
		System.out.print("Rate : " + rate + "\n");
		//Calculate interest
		double amount = (principle * time * rate) / 100;
		//Display amount
		System.out.print("Simple Interest : " + amount + "\n\n");
	}
	public static void main(String[] args)
	{
		MyMaths obj = new MyMaths();
		//Test Cases
		obj.simple_interest(1500, 3, 7.3);
		obj.simple_interest(170.4, 7, 3.4);
	}
}

Output

Principle : 1500.0
Time : 3.0
Rate : 7.3
Simple Interest : 328.5

Principle : 170.4
Time : 7.0
Rate : 3.4
Simple Interest : 40.55519999999999
/*
  C++ Program
  Calculate simple interest
*/
#include<iostream>

using namespace std;
class MyMaths
{
	public:
		//Method which is take three parameters
		//And calculates that simple interest
		//Here time is form in year
		//rate is form of annual interest rate
		void simple_interest(double principle, double time, double rate)
		{
			cout << "Principle : " << principle << "\n";
			cout << "Time : " << time << "\n";
			cout << "Rate : " << rate << "\n";
			//Calculate interest
			double amount = (principle * time * rate) / 100;
			cout << "Simple Interest : " << amount << "\n\n";
		}
};
int main()
{
	MyMaths obj ;
	//Test Cases
	obj.simple_interest(1500, 3, 7.3);
	obj.simple_interest(170.4, 7, 3.4);
	return 0;
}

Output

Principle : 1500
Time : 3
Rate : 7.3
Simple Interest : 328.5

Principle : 170.4
Time : 7
Rate : 3.4
Simple Interest : 40.5552
/*
  C# Program
  Calculate simple interest
*/
using System;
class MyMaths
{
	//Method which is take three parameters
	//And calculates that simple interest
	//Here time is form in year
	//rate is form of annual interest rate
	public void simple_interest(double principle, double time, double rate)
	{
		Console.Write("Principle : " + principle + "\n");
		Console.Write("Time : " + time + "\n");
		Console.Write("Rate : " + rate + "\n");
		//Calculate interest
		double amount = (principle * time * rate) / 100;
		Console.Write("Simple Interest : " + amount + "\n\n");
	}
	public static void Main(String[] args)
	{
		MyMaths obj = new MyMaths();
		//Test Cases
		obj.simple_interest(1500, 3, 7.3);
		obj.simple_interest(170.4, 7, 3.4);
	}
}

Output

Principle : 1500
Time : 3
Rate : 7.3
Simple Interest : 328.5

Principle : 170.4
Time : 7
Rate : 3.4
Simple Interest : 40.5552
<?php
/*
  Php Program
  Calculate simple interest
*/
class MyMaths
{
	//Method which is take three parameters
	//And calculates that simple interest
	//Here time is form in year
	//rate is form of annual interest rate
	function simple_interest($principle, $time, $rate)
	{
		echo "Principle : ". $principle ."\n";
		echo "Time : ". $time ."\n";
		echo "Rate : ". $rate ."\n";
		//Calculate interest
		$amount = ($principle * $time * $rate) / 100;
		echo "Simple Interest : ". $amount ."\n\n";
	}
}

function main()
{
	$obj = new MyMaths();
	//Test Cases
	$obj->simple_interest(1500, 3, 7.3);
	$obj->simple_interest(170.4, 7, 3.4);
}
main();

Output

Principle : 1500
Time : 3
Rate : 7.3
Simple Interest : 328.5

Principle : 170.4
Time : 7
Rate : 3.4
Simple Interest : 40.5552
/*
  Node Js Program
  Calculate simple interest
*/
class MyMaths
{
	//Method which is take three parameters
	//And calculates that simple interest
	//Here time is form in year
	//rate is form of annual interest rate
	simple_interest(principle, time, rate)
	{
		process.stdout.write("Principle : " + principle + "\n");
		process.stdout.write("Time : " + time + "\n");
		process.stdout.write("Rate : " + rate + "\n");
		//Calculate interest
		var amount = (principle * time * rate) / 100;
		process.stdout.write("Simple Interest : " + amount + "\n\n");
	}
}

function main()
{
	var obj = new MyMaths();
	//Test Cases
	obj.simple_interest(1500, 3, 7.3);
	obj.simple_interest(170.4, 7, 3.4);
}
main();

Output

Principle : 1500
Time : 3
Rate : 7.3
Simple Interest : 328.5

Principle : 170.4
Time : 7
Rate : 3.4
Simple Interest : 40.55519999999999
#   Python 3 Program
#   Calculate simple interest

class MyMaths :
	# Method which is take three parameters
	# And calculates that simple interest
	# Here time is form in year
	# rate is form of annual interest rate
	def simple_interest(self, principle, time, rate) :
		print("Principle : ", principle ,"\n", end = "")
		print("Time : ", time ,"\n", end = "")
		print("Rate : ", rate ,"\n", end = "")
		# Calculate interest
		amount = (principle * time * rate) / 100
		print("Simple Interest : ", amount ,"\n\n", end = "")
	

def main() :
	obj = MyMaths()
	# Test Cases
	obj.simple_interest(1500, 3, 7.3)
	obj.simple_interest(170.4, 7, 3.4)

if __name__ == "__main__": main()

Output

Principle :  1500
Time :  3
Rate :  7.3
Simple Interest :  328.5

Principle :  170.4
Time :  7
Rate :  3.4
Simple Interest :  40.55519999999999
#   Ruby Program
#   Calculate simple interest

class MyMaths

	# Method which is take three parameters
	# And calculates that simple interest
	# Here time is form in year
	# rate is form of annual interest rate
	def simple_interest(principle, time, rate)
	
		# Display parameters values
		print("Principle : ", principle ,"\n")
		print("Time : ", time ,"\n")
		print("Rate : ", rate ,"\n")
		# Calculate interest
		amount = (principle * time * rate) / 100
		# Display amount
		print("Simple Interest : ", amount ,"\n\n")
	end
end
def main()

	obj = MyMaths.new()
	# Test Cases
	obj.simple_interest(1500, 3, 7.3)
	obj.simple_interest(170.4, 7, 3.4)
end
main()

Output

Principle : 1500
Time : 3
Rate : 7.3
Simple Interest : 328.5

Principle : 170.4
Time : 7
Rate : 3.4
Simple Interest : 40.55519999999999

/*
  Scala Program
  Calculate simple interest
*/
class MyMaths
{
	//Method which is take three parameters
	//And calculates that simple interest
	//Here time is form in year
	//rate is form of annual interest rate
	def simple_interest(principle: Double, time: Double, rate: Double): Unit = {
		//Display parameters values
		print("Principle : " + principle + "\n");
		print("Time : " + time + "\n");
		print("Rate : " + rate + "\n");
		//Calculate interest
		var amount: Double = (principle * time * rate) / 100;
		//Display amount
		print("Simple Interest : " + amount + "\n\n");
	}
}
object Main
{
	def main(args: Array[String]): Unit = {
		var obj: MyMaths = new MyMaths();
		//Test Cases
		obj.simple_interest(1500, 3, 7.3);
		obj.simple_interest(170.4, 7, 3.4);
	}
}

Output

Principle : 1500.0
Time : 3.0
Rate : 7.3
Simple Interest : 328.5

Principle : 170.4
Time : 7.0
Rate : 3.4
Simple Interest : 40.55519999999999
/*
  Swift Program
  Calculate simple interest
*/
class MyMaths
{
	//Method which is take three parameters
	//And calculates that simple interest
	//Here time is form in year
	//rate is form of annual interest rate
	func simple_interest(_ principle: Double, _ time: Double, _ rate: Double)
	{
		print("Principle : ", principle ,"\n", terminator: "");
		print("Time : ", time ,"\n", terminator: "");
		print("Rate : ", rate ,"\n", terminator: "");
		//Calculate interest
		let amount: Double = (principle * time * rate) / 100;
		print("Simple Interest : ", amount ,"\n\n", terminator: "");
	}
}
func main()
{
	let obj: MyMaths = MyMaths();
	//Test Cases
	obj.simple_interest(1500, 3, 7.3);
	obj.simple_interest(170.4, 7, 3.4);
}
main();

Output

Principle :  1500.0
Time :  3.0
Rate :  7.3
Simple Interest :  328.5

Principle :  170.4
Time :  7.0
Rate :  3.4
Simple Interest :  40.5552

Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment







© 2021, kalkicode.com, All rights reserved