Kotlin Program to Display Factors of a Number: In the below program, the number whose factors are to be found is stored in the variable number (60). The for loop is iterated from 1 to number.
Kotlin Program to Display Factors of a Number
Source Code
fun main(args: Array<String>) {
val number = 60
print("Factors of $number are: ")
for (i in 1..number) {
if (number % i == 0) {
print("$i ")
}
}
}
Output
Kotlin Program to Display Factors of a Number