Problem Statement
Write a C Program to find missing number in an array contains 1 to 100 Nos without sorting.
Note: This c program will helps us to find the missing no in an array without sorting and this is the one of logical c program question asked in technical interview
Solution
#include<stdio.h>
int main()
{
int a[101]={0},t,sum=0,i;
for(i=1;i<=100;i++)// assigning the values to an array using this for loop
{
if(i!=89)//we are not storing 89 value bcz we consider its a missing no.
a[i]=i;
}
t=(100/2)*((100+1));//formula for finding sum of n natural nos in c program
for(i=1;i<=100;i++)
{
sum=sum+a[i];//sum of all the elements in an array.
}
printf("Missing number is %d",t-sum);
}
Output
Missing number is 89.