top of page

Missing Number



#include <stdio.h>


int main() {

int size;

printf("\nEnter the size : ");

scanf("%d",&size);

int a[size];

int i=0,sum=0,n,msng_no;

n=size+1;

for(i=0;i<size;i++)

{

printf("\nEnter element : ");

scanf("%d",&a[i]);

}

printf("\nArray elements\n");

for(i=0;i<size;i++)

{

printf("%d ",a[i]);

}

for(i=0;i<size;i++)

{

sum=sum+a[i];

}

msng_no=(n*(n+1))/2 - sum;

printf("\nMissing Number : %d",msng_no);

}



Recent Posts

See All
Stack Using Queue

A stack can be implemented using two queues in C. The basic idea is to use one queue for enqueue operations and another for dequeue...

 
 
 
Queue Using Stack

A queue can be implemented using two stacks in C. The basic idea is to use one stack for enqueue operations and another for dequeue...

 
 
 
Queue Using Array

#include <stdio.h> #include<stdlib.h> #include<math.h> #define size 5 int queue[size]; int front = -1; int rear = -1; void enque(void);...

 
 
 

Commenti


bottom of page