Minimum number of Array

fun main() {
    println("Enter the size of Array")//1
    val size = readLine()?.toInt()!!//2
    val numbers = IntArray(size)//3
    for (i in 0 until size) {//4
        numbers[i] = readLine()?.toInt()!!//5
   }
    var smallerno = numbers[0]//6
    for (i in numbers) {//7
        if (i > smallerno) {//8
            smallerno = i//9
        }
    }
    println("Smaller No of Array Element=$smallerno")//10
}
  1. Instruct the user to Enter the size of the Array
  2. Convert the entered value into int and assign to size variable
  3. Create an array to Int of a given size
  4. Execute the for loop from 0 to less than the size
  5. Initialized the elements of array by user-entered values
  6. Create and initialize the value of the variable smallerno by the first element of an array
  7. Execute for loop statement to find the smaller number from the given array
  8. if Condition to check a smaller number of all array elements
  9. Assign the value of smaller element and assign to smallerno
  10. Print the output of Smaller Element of console

Output

Enter the size of Array
5
10
30
56
79
56
Smaller No of Array Element=79

Leave a Reply

Your email address will not be published. Required fields are marked *