Programming Articles - Page 581 of 3363

Kotlin Program to Find all Roots of a Quadratic Equation

AmitDiwan
Updated on 13-Oct-2022 13:13:35

883 Views

In this article, we will understand how to calculate the roots of a quadratic equation in Kotlin. A quadratic equation is an algebraic expression of the second degree or in other words, it has two results i.e., real number and an imaginary number. Below is a demonstration of the same Suppose our input is − a = 1, b = 2, c = 3 The desired output would be − The roots of the quadratic equation are root1 = -1.00+1.41i root2 = -1.00-1.41i Algorithm Step 1 − Start Step 2 − Declare six values: inputA, inputB, inputC, ... Read More

Kotlin Program to Find the Largest Among Three Numbers

AmitDiwan
Updated on 13-Oct-2022 13:11:20

1K+ Views

In this article, we will understand how to find the largest of three integers in Kotlin. This is done using a greater than operator (= input2 && input1 >= input3) println("The first value i.e $input1 is the largest number.") else if (input2 >= input1 && input2 >= input3) println("The second value i.e $input2 is the largest number.") else println("The third value i.e $input3 is the largest number.") Let us now see the complete example to find the largest among three numbers in Kotlin − fun main() { ... Read More

Kotlin Program to Compute Quotient and Remainder

AmitDiwan
Updated on 13-Oct-2022 13:09:04

696 Views

In this article, we will understand how to compute the quotient and reminder in Kotlin. Quotient and Reminder is calculated using two simple formulae − “Quotient = Dividend / Divisor” “Remainder = Dividend % Divisor” Below is a demonstration of the same Suppose our input is − Dividend value: 50 Divisor: 3 The desired output would be − Quotient: 16 Remainder: 2 Algorithm Step 1 − Start Step 2 − Declare four integers as myDividend , myDivisor, resultQuotient, resultRemainder Step 3 − Define the integers Step 4 − Use the formula to find the quotient and ... Read More

Kotlin Program to Print the ASCII values

AmitDiwan
Updated on 13-Oct-2022 13:06:58

1K+ Views

In this article, we will understand how to print ascii values of characters. This is done by assigning the character to an integer value and printing those integer values. Below is a demonstration of the same Suppose our input is − Enter a character: s The desired output would be − Ascii value of s is 115 Algorithm Step 1 − Start Step 2 − Declare a char as input Step 3 − Define the character Step 4 − Assign the character to an integer variable using toInt() function and store it in myResult. Step 5 − ... Read More

Kotlin Program to Find the Surface Area and Volume of Cuboid

AmitDiwan
Updated on 13-Oct-2022 13:04:44

301 Views

In this article, we will understand how to compute the surface area and volume the cuboid. The surface area of cuboid is calculated using the formula − 2*( length *width + width* height + height*length) The Volume of the cuboid is calculated using the formula length*width*height Below is a demonstration of the same − Suppose our input is − length= 6; width= 7; height= 8; The desired output would be − Volume Of the Cuboid is : 336.0 Surface area Of the Cuboid is : 292.0 Algorithm Step 1 − START Step 2 − Declare ... Read More

Kotlin Program to Find the Area of a Circle

AmitDiwan
Updated on 13-Oct-2022 13:02:26

1K+ Views

In this article, we will understand how find the area of a circle. Area of a circle is calculated by using the formula − (pie*radius*radius)/7 Below is a demonstration of the same Suppose our input is Radius of the circle: 5 The desired output would be − The Area of Circle is: 78.57142857142857 Algorithm Step 1 − START Step 2 − Declare two variables radius and myResult Step 3 − Read the value of the radius from the user Step 4 − Calculate the area of the circle by using the formula (22*radius*radius)/7 and store the ... Read More

Kotlin Program to Find the Perimeter of a Rectangle

AmitDiwan
Updated on 13-Oct-2022 13:00:11

585 Views

In this article, we will understand how to find the perimeter of a rectangle. The Perimeter of a rectangle is calculated using the following formulae 2*(length + width) Below is a demonstration of the same − Suppose our input is The length of the sides of a rectangle are: 5, 8, 5, 8 The desired output would be Perimeter : 26 Algorithm Step 1 − START Step 2 − Declare three integer variables length, width and myResult. Step 3 − Define the values. Step 4 − Calculate the perimeter using the formula 2 * (length + ... Read More

Kotlin Program to Calculate Compound Interest

AmitDiwan
Updated on 13-Oct-2022 12:57:52

591 Views

In this article, we will understand how to calculate the Compound interest. The percentage interest charged on principal and accrued interest is Compound Interest. Rates are higher compared to Simple Interest. Compound Interest is calculated using the formula principle * (Math.pow((1 + rate / 100), time)) – principle Below is a demonstration of the same Suppose our input is Principle number: 100000 Interest rate: 5 Time period in years: 3 The desired output would be − The Compound Interest is: 15762.50000000001 Algorithm Step 1 − START Step 2 − Declare four integer values principalAmount, interestRate, timePeriod, ... Read More

Kotlin Program to Calculate Simple Interest

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

467 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

Advertisements