Friday 22 July 2016

Q.1 Find Three Largest Numbers from an Unsorted Array ,using single for loop,without sorting.? i/p: Array [10,18,73,2,84,9,20,66,22] o/p:first:84, second:73, third:66
public class ThreeLargest { public static void main(String[] args) { int f=0,s=0,t=0; int[] x={10,18,73,2,84,9,20,66,22}; for(int i=0;i<x.length;i++){ if(x[i]>f){ t=s;s=f;f=x[i]; }else if(x[i]>s){a t=s;s=x[i]; }else if(x[i]>t){ t=x[i]; } } System.out.println("first :"+f+" second :"+s+ " third :"+t); } }

5 comments:

  1. Thanks Laxman,But Why don't you show output?

    ReplyDelete
    Replies
    1. Thank you Sravan I consider your feedback :)

      Delete
  2. Why don't provide output ?

    ReplyDelete
    Replies
    1. Thank you vishnu I consider your feedback :)

      Delete
  3. great work laxman... but we want programs in c language also..

    ReplyDelete

Featured post

All Logical Questions are Answered JumpInToIt