Kotlin Program to Display Factors of a Number

bookmark

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:

Factors of 60 are: 1 2 3 4 5 6 10 12 15 20 30 60