write a program to find maximum number in an array of 10 numbers
Answers
Answer:
Java program to find largest number in an array
Initialize array value.
Step 2: (int max = a[0];) Initialize max value as array's first value.
Step 3: (for int i = 1; i < a.length; i++ ) ...
Step 4: if(a[i] > max)
Continue the loop and resign the max value if array current value is greater than max.
Program. ...
Output.
return 0;
Declare an array of user-defined size.
Using for loop, define the elements of the array.
Consider the first element of array to be the first largest number (store it in a variable, largest1).
Consider the second element of array to be the second-largest number (store it in a variable, largest2).
Let's see another example to get second largest number in java array using collections.
import java.util.*;
public class SecondLargestInArrayExample2{
public static int getSecondLargest(Integer[] a, int total){
List<Integer> list=Arrays.asList(a);
Collections.sort(list);
int element=list.get(total-2);
return elemen
Algorithm to find the smallest and largest numbers in an array
Input the array elements.
Initialize small = large = arr[0]
Repeat from i = 2 to n.
if(arr[i] > large)
large = arr[i]
if(arr[i] < small)
small = arr[i]
Print small and large.
The simplest procedural way to get the value of the length of an array is by using the sizeof operator. First you need to determine the size of the array. Then you need to divide it by the size of one element. It works because every item in the array has the same type, and as such the same size.The program output is shown below.
#include<iostream>
int A[10], n, i, j, x;
cout << "Enter size of array : ";
cin >> n;
cout << "Enter elements of array : ";
for (i = 0; i < n; i++)
cin >> A[i];
for (i = 0; i < n;
HOPE it helps you and mark me as a braienlist and follow me