Kotlin Program to Display Factors of a Number: In the above 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. In each iteration, whether the number is exactly divisible by i is checked (condition for I to be the factor of number) and the value of i is incremented by 1.
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