Programming Articles

Page 1987 of 2547

Kotlin Program to Display All Prime Numbers from 1 to N

AmitDiwan
AmitDiwan
Updated on 13-Oct-2022 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
AmitDiwan
Updated on 13-Oct-2022 712 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
AmitDiwan
Updated on 13-Oct-2022 889 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

Kotlin Program to Add Two Complex numbers

AmitDiwan
AmitDiwan
Updated on 13-Oct-2022 642 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

Kotlin Program to Multiply Two Floating-Point Numbers

AmitDiwan
AmitDiwan
Updated on 13-Oct-2022 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

Kotlin Program to Read The Number From Standard Input

AmitDiwan
AmitDiwan
Updated on 13-Oct-2022 551 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

Kotlin Program to Swap Two Numbers

AmitDiwan
AmitDiwan
Updated on 13-Oct-2022 1K+ Views

In this article, we will understand how to how to swap two numbers in Kotlin. This is done using a temporary variable. Below is a demonstration of the same Suppose our input is val1 : 45 val2 : 60 The desired output would be val1 : 60 val2 : 45 Algorithm Step 1 − Start Step 2 − Declare three integers: val1, val2 and tempVal Step 3 − Define the values Step 4 − Assign val1 to temporary variable Step 5 − Assign val2 to val1 Step 6 − Assign temporary tempVal variable to val2 Step 7 ...

Read More

Kotlin Program to Add two Numbers

AmitDiwan
AmitDiwan
Updated on 13-Oct-2022 5K+ Views

In this article, we will understand how to add two numbers. This can be done using the ‘+’ operator. Below is a demonstration of the same Suppose our input is input1 : 10 input2 : 15 The desired output would be Sum : 25 Algorithm Step 1 − Start Step 2 − Declare three integers: val1, val2 and sum Step 3 − Define the integers Step 4 − Add the two values using an addition operator (+) Step 5 − Display the result Step 6 − Stop Example 1 In this example, we will add two numbers ...

Read More

Kotlin Program to Print an Integer

AmitDiwan
AmitDiwan
Updated on 13-Oct-2022 764 Views

In this article, we will understand how to print an integer. Integer is a primitive data type that contains numbers up to 32 bits. Below is a demonstration of the same − Suppose our input is − 45 The desired output would be − The integer is: 45 Algorithm Step 1 − START Step 2 − Define the integer value in a variable Step 3 − Display it on the console Step 4 − STOP Example 1 In this example, we will simply print an integer using the print() method. First, declare an integer variable, which ...

Read More

Hello World program in Kotlin

AmitDiwan
AmitDiwan
Updated on 13-Oct-2022 593 Views

In this article, we will understand how to print hello world in Kotlin. Hello world is stored as a string format and is printed using ‘print()’ function. Input Suppose our input is Hello World Output The expected out should be Hello World Algorithm Step 1 − START Step 2 − Define a string variable Step 3 − Display the string on the console Step 4 − STOP Example 1 In this example, we will simply display a string “Hello World” using the print() method in Kotlin − fun main() { val inputStr = ...

Read More
Showing 19861–19870 of 25,466 articles
Advertisements