C Program to Find Missing Numbers in Array

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.

  1. /* 
  2.  * C Program to identify missing numbers in a given array
  3.  */
  4. #include <stdio.h>
  5.  
  6. void main()
  7. {
  8.     int n, i, j, c, t, b;
  9.  
  10.     printf("Enter size of array : ");
  11.     scanf("%d", &n);
  12.     int array[n - 1];     /* array size-1 */
  13.     printf("Enter elements into array : \n");
  14.     for (i = 0; i < n - 1; i++)    
  15.         scanf("%d", &array[i]);
  16.     b = array[0];
  17.     for (i = 1; i < n - 1; i++)
  18.         b = b ^ array[i];
  19.     for (i = 2, c = 1; i <= n; i++)
  20.         c = c ^ i; 
  21.     c = c ^ b;  
  22.     printf("Missing element is : %d \n", c);
  23. }

$ 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

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.

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
I’m Manish - Founder and CTO at Sanfoundry. I’ve been working in tech for over 25 years, with deep focus on Linux kernel, SAN technologies, Advanced C, Full Stack and Scalable website designs.

You can connect with me on LinkedIn, watch my Youtube Masterclasses, or join my Telegram tech discussions.

If you’re in your 40s–60s and exploring new directions in your career, I also offer mentoring. Learn more here.