top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to find missing number from arraylist, numbers added randomly?

+1 vote
689 views

Any sample code in C or Java would be helpful?

posted May 13, 2015 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

This is simple, just search through your array list for that specific number which you want to make sure that
number is missing or present the array list.
Have a look to the sample code below:

#include <stdio.h>

int main()
{
    int arr[10];
    int i, no, missing = 1;

    printf("Enter 10 random number one by one:\n");
    for (i = 0; i < 10; i++)
        scanf("%d", &arr[i]);

    printf("Enter number which you want to find : ");
    scanf("%d", &no);

    for(i = 0; i < 10; i++) {
        if (no == arr[i])
            missing = 0;
    }

    if (missing)
        printf("%d is missing in the given array list.\n", no);
    else
        printf("%d is present in the given array list.\n", no);

    return 0;
}
answer May 14, 2015 by Arshad Khan
Similar Questions
–1 vote

Say you are given two arrays where second array is duplicate with one missing element. What should be the best possible way to find that missing element -
array1: [1,2,3,4,5,6,7]
array2: [1,3,4,5,6,7]

Missing Element: 2

0 votes

Given an unsorted array which has a number in the majority (a number appears more than 50% in the array), how to find that number?

...