Maximum 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 numbers)//4
    {
        numbers[i]= readLine()?.toInt()!!//5
    }
    var greaterno=numbers[0]//6
    for(i in numbers)//7
    {
        if(i>greaterno)//8
        {
            greaterno = i//9
        }
    }
    println("Greater No of Array Element=$greaterno")//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 greaterno by the first element of an array
  7. Execute for loop statement to find the greater number from the given array
  8. if Condition to check a greater number of all array elements
  9. Assign the value of greater element and assign to greaterno
  10. Print the output of Greater Element of console

Output

Enter the size of the Array
5
10
45
67
9
90
Greater No of Array Element=90

Leave a Reply

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