Showing posts with label 1-n sorted numbers. Show all posts
Showing posts with label 1-n sorted numbers. Show all posts

Saturday, August 18, 2012

Array 1-100 numbers are stored, one number is missing how do you find the number


//Find missing Number in array 1-10;

public class MissingNumberInArray {

public static void main(String args[]){

int a[]={1,2,3,4,5,6,7,8,10};
int asum = 0,sum = 0;
for(int i=1;i<=10;i++)
sum=sum+i;
for(int i=0;i<a.length;i++)
asum=asum+a[i];
int missnum=sum-asum;
System.out.println("Missing Number"+missnum);
}
}