This C Program identifies missing numbers in a given array.
Here is source code of the C Program to identify missing numbers in a given array. The C program is successfully compiled and run on a Linux system. The program output is also shown below.
/*
* C Program to identify missing numbers in a given array
*/
#include <stdio.h>
void main()
{
int n, i, j, c, t, b;
printf("Enter size of array : ");
scanf("%d", &n);
int array[n - 1]; /* array size-1 */
printf("Enter elements into array : \n");
for (i = 0; i < n - 1; i++)
scanf("%d", &array[i]);
b = array[0];
for (i = 1; i < n - 1; i++)
b = b ^ array[i];
for (i = 2, c = 1; i <= n; i++)
c = c ^ i;
c = c ^ b;
printf("Missing element is : %d \n", c);
}
$ cc bit30.c $ a.out Enter size of array : 6 Enter elements into array : 1 2 3 5 6 Missing element is : 4
Sanfoundry Global Education & Learning Series – 1000 C Programs.
advertisement
advertisement
Here’s the list of Best Books in C Programming, Data-Structures and Algorithms
If you wish to look at programming examples on all topics, go to C Programming Examples.
If you find any mistake above, kindly email to [email protected]Related Posts:
- Check C Books
- Practice Computer Science MCQs
- Practice BCA MCQs
- Check Computer Science Books
- Apply for C Internship