Write a Kotlin Program to Multiply two Floating Point Numbers

In Kotlin, multiplying two floating point numbers is a straightforward task.

You can use the asterisk symbol (*) to perform multiplication.

Here is a simple program to multiply two floating point numbers:

fun main() {
val num1 = 4.5f
val num2 = 2.0f
val result = num1 * num2
println("The product of $num1 and $num2 is $result")
}

In the above code, we have declared two variables num1 and num2 with floating point values of 4.5 and 2.0 respectively.

We then multiplied these two numbers using the asterisk (*) operator and stored the result in a new variable called result.

Finally, we printed the result using the println() function.

You can modify this program by accepting user input for the two numbers. Here’s how you can do it:

fun main() {
println("Enter two floating point numbers:")
val num1 = readLine()!!.toFloat()
val num2 = readLine()!!.toFloat()
val result = num1 * num2
println("The product of $num1 and $num2 is $result")
}

In the above code, we first prompt the user to enter two floating point numbers.

We then use the readLine() function to read the input from the user and convert it to a floating point value using the toFloat() function.

We then multiply the two numbers and store the result in a new variable called result.

Finally, we print the result using the println() function.

In conclusion, multiplying two floating point numbers in Kotlin is a simple task that can be accomplished using the asterisk (*) operator.

You can either hardcode the values or accept user input for the two numbers, depending on your requirements.