Skip to content
This repository was archived by the owner on Dec 12, 2023. It is now read-only.

Commit e74f475

Browse files
committed
Added solution to find-missing-element in C.
1 parent 0e1acad commit e74f475

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

solutions/c/find-missing-element.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
// The differnce in sum of two arrays will give us the desired value.
4+
// The other approach could be to look up for element each time but that will increase the time complexity of the program.
5+
int find_missing(int orig[],int On,int shuffled[])
6+
{
7+
int i,sum=0;
8+
for(i=0;i<On-1;i++)
9+
sum+=orig[i]-shuffled[i];
10+
return sum+orig[On-1];
11+
}
12+
13+
int main()
14+
{
15+
int arr[]={1,3,5,6,2,5,6,8,9,23,45,67,87};
16+
int shuffled_arr[]={1,2,5,6,8,9,3,45,87,6,67,5};
17+
int On=sizeof(arr) / sizeof(arr[1]);
18+
printf("The missing value is:%d\n",find_missing(arr,On,shuffled_arr));
19+
return 0;
20+
}

0 commit comments

Comments
 (0)