Computer Science, asked by anonymousforschool, 6 hours ago

Write a program to find the minimum of 10 numbers
(use this "for(i=1;i<=10;i++)")

Answers

Answered by anindyaadhikari13
1

Solution.

The given problem is solved using language - Java.

import java.util.*;

public class MinList{

   public static void main(String s[]){

       Scanner sc=new Scanner(System.in);

       System.out.println("Enter 10 numbers..");

       int a[]=new int[10];

       int min,i;

       for(i=0;i<10;i++){

           System.out.print("a["+i+"] = ");

           a[i]=sc.nextInt();

       }

       sc.close();

       min=a[0];

       for(i=1;i<10;i++){

           if(a[i]<min)

               min=a[i];

       }

       System.out.println("Given Array: "+Arrays.toString(a));

       System.out.println("Minimum Element: "+min);

   }

}

Here, we have assumed that the first element of the array is the smallest number.

Now, we will transverse through array elements. If any element is found less than minimum value, the element is stored in min variable.

At last, the min variable is displayed.

See attachment for output.

Attachments:
Similar questions