Skip to content

Commit 69e0011

Browse files
Missing number
to find the missing number
1 parent c5c05c2 commit 69e0011

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Find missing number

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <stdio.h>
2+
3+
/* getMissingNo takes array and size of array as arguments*/
4+
int getMissingNo(int a[], int n)
5+
{
6+
int i, total;
7+
total = (n + 1) * (n + 2) / 2;
8+
for (i = 0; i < n; i++)
9+
total -= a[i];
10+
return total;
11+
}
12+
13+
/*program to test above function */
14+
int main()
15+
{
16+
int a[] = { 1, 2, 4, 5, 6 };
17+
int miss = getMissingNo(a, 5);
18+
printf("%d", miss);
19+
getchar();
20+
}

0 commit comments

Comments
 (0)