Skip to main content

Program to calculate simple interest in swift

Swift Program to calculate simple interest. Here mentioned other language solution.

import Foundation
//  Swift program for
//  Calculate simple interest
class Interest
{
    // Method which is take three parameters
    // And calculates that simple interest
    // Here time is form in year
    // rate is form of annual interest rate
    static func simpleInterest(_ principle : Double, 
                               _ time : Double, 
                               _ rate : Double)
    {
        // Display parameters values
        print("Principal : ",principle);
        print("Time : ",time);
        print("Rate : ",rate);
        // Calculate interest
        let amount : Double = (principle * time * rate) / 100;
        // Display amount
        print("Simple Interest : ",amount);
    }
}

 // Test Cases
Interest.simpleInterest(1500,3,7.3);
Interest.simpleInterest(170.4,7,3.4);

Output

Principal :  1500.0
Time :  3.0
Rate :  7.3
Simple Interest :  328.5
Principal :  170.4
Time :  7.0
Rate :  3.4
Simple Interest :  40.5552




Comment

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