by Dinesh Thakur Category: array

Algorithm for Largest Number in an Array:


step 1: set big=0,small=0

step 2: read arr_size

step 3: create an integer array a[] of size arr_size

step 4: initialize x=0

step 5: repeat through step-7 while x less than a.length

step 6: read a[x]

step 7: x= x+ 1

step 8: Initialize x=0

step 9: repeat through step-12 while x less than a.length

step 10: print a[x]

step 11: print one space

step 12: x=x+1

step 13: initialize x=0

step 14: repeat through step-16 while x less than a.length

step 15: if a[x] greater than big then big=a[x]

step 16: x=x+1

step 17: print big

step 18: Exit

Here is the Java Example for Largest Number in an Array:

import java.util.Scanner;

public class LargestNumberinArray
              public static void main(String args[])
              int x,y,big=0,small=0;
              Scanner sl=new Scanner(;
              System.out.print("Enter The Size of Array : ");
              int a[]=new int[y];
              System.out.println("Enter The Elements");
              System.out.println("\n Print The Elements of Array \n" );
              System.out.print(a[x]+" ");
System.out.println("Largest Number in an Array is : "+big);

Largest Number in an Array

Popular Article