forked from mrizky-kur/Redux-toolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Missing Number.cpp
69 lines (59 loc) · 1.13 KB
/
Missing Number.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <iostream>
using namespace std;
void sorting(int arr[], int size){
int temp,min;
for(int i=0;i<=size-1;i++){
for(int j=i+1;j<size;j++){
if(arr[i]>arr[j]){
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
}
}
int MissingNumber(int arr[],int size){
sorting(arr,size);
cout<<"After sorting"<<endl;
for(int i=0;i<size;i++){
cout<<arr[i]<<" ";
}
// int totalsum=(size + 1) + size * (size + 1)/2;
// int sum=0;
// for(int i=0;i<size-1;i++){
// sum=+arr[i];
// }
// int missingNumber=totalsum-sum;
// cout<<"\nMissing Number";
// cout<<endl<<missingNumber;
int i=0,k=1;
while(i<size){
if(arr[i]==k){
i++;
k++;
}
else{
cout<<"\n"<<k<<" is missing";
k++;
}
}
// for(int i=0;i<size;i++){
// int temp=arr[i]+1;
// cout<<temp;
// if(arr[i++]!=temp){
// //cout<<temp<<" is not available";
// }
//
// }
}
int main(){
int size;
cout<<"Enter the size of Array=";
cin>>size;
int arr[size];
cout<<"Enter the elements of array"<<endl;
for(int i=0;i<size;i++){
cin>>arr[i];
}
MissingNumber(arr,size);
}