Program to identify missing number in entered array using function

1 year ago Admin 0

Identify missing number in entered array using function

This article illustrates the concept how to identify missing number in entered array using function in c/c++.

identify missing number in entered array using function

Here is the source code and output of both the programs.

C Programming language

Program


#include<stdio.h>
#include<conio.h>
int missingnumber(int[],int);
void main()
{
 int arr[100],size,i,result;
 clrscr();
 printf("Enter number of elements you want to print in array:- ");
 scanf("%d",&size);
 printf("Enter elements in array:- \n");
 for(i=0;i<size;i++)
  {
   scanf("%d",&arr[i]);
  }
 result=missingnumber(arr,size);
 printf("Missing number is:- %d",result);
 getch();
}
int missingnumber(int arr[],int size)
 {
  int i,missing;
  missing=(size+1)*(size+2)/2;
  for(i=0;i<size;i++)
   {
    missing=missing-arr[i];
   }
  return missing;
 }

After successfully compiling and executing the above C program,output is:-

identify missing number in entered array using function


C++ Programming language

Program


#include<iostream.h>
#include<conio.h>
int missingnumber(int[],int);
void main()
{
 clrscr();
 int arr[100],size,i,result;
 cout<<"Enter number of elements you want to print in array:- ";
 cin>>size;
 cout<<"Enter elements in array:-"<<endl;
 for(i=0;i<size;i++)
  {
   cin>>arr[i];
  }
 result=missingnumber(arr,size);
 cout<<"Missing number is:-"<<result;
 getch();
}
int missingnumber(int arr[],int size)
 {
  int i,missing;
  missing=(size+1)*(size+2)/2;
  for(i=0;i<size;i++)
   {
    missing=missing-arr[i];
   }
  return missing;
 }

After successfully compiling and executing the above C++ program,output is:-

identify missing number in entered array using function


Comment below if you are facing any problem or you find any error in the above program and also subscribe to our newsletter for more updates.


Read more c/c++ Programs published by snapcout:-

Program to find greatest between three numbers using function
Program to insert an element in array using function
Program to search an element in array using function
Program to find largest element in array using function
Program to swap two numbers using function


About article

Written By:- Admin

Published on:- 01/08/2018

Published By:- Snapcout


Don't forget to share the article if you like it:-