Kotlin Program to Calculate Simple Interest

AmitDiwan
Updated on 13-Oct-2022 12:53:38

436 Views

In this article, we will understand how to calculate the Simple Interest in Kotlin. It is the percentage interest on total principal amount. Returns are less compared to Compound Interest. Simple Interest is calculated using the formula (principle*rate*time)/100 Below is a demonstration of the same Suppose our input is Principle number: 100000 Interest rate: 5 Time period in years: 2 The desired output would be Simple Interest: 1000 Algorithm Step 1 − START Step 2 − Declare four integer values principalAmount, interestRate, timePeriod, simpleInterest Step 3 − Define the values for principalAmount, interestRate, timePeriod, simpleInterest Step ... Read More

Kotlin Program to Find Factorial of a Number

AmitDiwan
Updated on 13-Oct-2022 12:51:24

2K+ Views

In this article, we will understand how to find the factorial of a number. Factorial of a number is the product of itself with each of its lower numbers. Below is a demonstration of the same − Suppose our input is Enter the number : 5 The desired output would be − The factorial of 5 is 120 Algorithm Step 1 − Start Step 2 − Declare three integers: input, myResult and i Step 3 − Hardcode the integer Step 4 − Run a for-loop, multiply the number with its lower number and run the loop till ... Read More

Check Armstrong Number Between Two Integers in Kotlin

AmitDiwan
Updated on 13-Oct-2022 12:49:28

831 Views

In this article, we will understand how to display the Armstrong numbers between the given two numbers in Kotlin. An Armstrong number is a number that is equal to the sum of the cubes of its own digits. For example, 153 is 153 = (1)3 + (5)3 + (3)3 Below is a demonstration of the same Suppose our input is 1 & 500 The desired output would be The Armstrong numbers between 1 and 500 are 2, 3, 4, 5, 6, 7, 8, 9, 153, 370, 371, 407 Algorithm Step 1 − Start Step 2 − ... Read More

Kotlin Program to Display Alphabets A to Z Using Loop

AmitDiwan
Updated on 13-Oct-2022 12:47:18

1K+ Views

In this article, we will understand how to print alphabets from A to Z or a to z in Kotlin. This is accomplished using a simple for-loop. Below is a demonstration of the same Suppose our input is A to Z The desired output would be A B C D E F G H I J K L M N O P Q R S T U V W X Y Z Algorithm Step 1 − Start Step 2 − Declare a character variable: input Step 3 − Run a while loop with condition input greater that ... Read More

Kotlin Program to Display All Prime Numbers from 1 to N

AmitDiwan
Updated on 13-Oct-2022 12:44:06

4K+ Views

In this article, we will understand how to display all the prime numbers from 1 to N in Kotlin. All possible positive numbers from 1 to infinity are called natural numbers. Prime numbers are special numbers who have only two factors 1 and itself and cannot be divided by any other number. Below is a demonstration of the same Suppose our input is − Value of n :10 The desired output would be − 2 3 5 7 Algorithm Step 1 − Start Step 2 − Declare two integers: low and high Step 3 − Define the ... Read More

Kotlin Program to Find LCM of Two Numbers

AmitDiwan
Updated on 13-Oct-2022 12:42:32

644 Views

In this article, we will understand how to calculate the LCM of two numbers in Kotlin. Lowest Common Multiple (LCM) of two numbers is the smallest positive integer that is evenly divisible by both the numbers. Below is a demonstration of the same Suppose our input is 24 and 18 The desired output would be The LCM of the two numbers is 72 Algorithm Step 1 − Start Step 2 − Declare three integers: input1, input2 and myResult Step 3 − Define the values Step 4 − Using a while loop from 1 to the bigger number ... Read More

Kotlin Program to Find GCD of Two Numbers

AmitDiwan
Updated on 13-Oct-2022 12:39:09

811 Views

In this article, we will understand how to find the GCD of two numbers in Kotlin. Greatest Common Divisor (GCD) of two numbers is the largest number that divides both. Below is a demonstration of the same Suppose our input is Value 1 : 18 Value 2 : 24 The desired output would be GCD of the two numbers: 6 Algorithm Step 1 − Start Step 2 − Declare three integers: input1, input2 and myResult Step 3 − Define the integer Step 4 − Check that the number divides both (input1 and input2) numbers completely or not. ... Read More

Add Two Complex Numbers in Kotlin

AmitDiwan
Updated on 13-Oct-2022 12:37:13

552 Views

In this article, we will understand how to add two complex numbers in Kotlin. They have the ‘I’ that is, an imaginary part associated with it. Below is a demonstration of the same − Suppose our input is 15 +i24 and 3 +i7 The desired output would be 18 +i31 Algorithm Step 1 − Start Step 2 − Declare three Complex numbers: inputValue1, inputValue2 and myResult Step 3 − Hardcode the complex number values Step 4 − Define a function addComplexNumber, wherein you add the real numbers and the imaginary numbers separately and return the result. Step ... Read More

Multiply Two Floating Point Numbers in Kotlin

AmitDiwan
Updated on 13-Oct-2022 12:34:58

2K+ Views

In this article, we will understand how to multiply two floating-point numbers. A floating-point number, is a positive or negative whole number with a decimal point. There are two types of floating point in Kotlin Float Double Below is a demonstration of the same − Suppose our input is val1: 10.5 val2: 45.0 The desired output would be The product is: 472.5 Algorithm Step 1 − Start Step 2 − Declare three floating points: val1, val2 and product Step 3 − Define the floating-point values Step 4 − Read the values Step 5 − Multiply ... Read More

Read Number from Standard Input in Kotlin

AmitDiwan
Updated on 13-Oct-2022 12:28:31

463 Views

In this article, we will understand how to read a number from standard input in Kotlin. The ‘nextInt’ method is used to read the number. Below is a demonstration of the same Suppose our input is 45 The desired output would be The input value is 45 Algorithm Step 1 − Start Step 2 − Declare an integer: value Step 3 − Define the integer Step 4 − Read the values Step 5 − Display the value Step 6 − Stop Example 1 In this example, we will read the number from the standard input using ... Read More

Advertisements