Write a C program to find the missing integer among the array of integers that are in the range 1 to n. 
Input Format: 
The first line of the input consists of an integer, n that corresponds to the number of elements in the input array. 
The next 'n' lines in the input correspond to the elements in the array. 
Output Format: 
Output is an integer. 
Refer sample input and output for formatting specifications. 

Sample Input1: 
Sample Output1: 
  
Sample Input2: 
Sample Output2: 


Program Code:
#include<stdio.h>
int getMissingNo (int a[], int n)
{
    int i, total;
    total  = (n+1)*(n+2)/2;   
    for ( i = 0; i< n; i++)
       total -= a[i];
    return total;
}
int main()
{
    int a[100], i, n;
    scanf("%d", &n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    int miss = getMissingNo(a,n);
    printf("%d", miss);
    return 0;
}

Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: