-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathc15.c
More file actions
49 lines (45 loc) · 965 Bytes
/
c15.c
File metadata and controls
49 lines (45 loc) · 965 Bytes
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
//Missing number in array [1 to n]
#include<stdio.h>
int main()
{
int n;
scanf("%d",&n);
int a[n-1];
int sum=0;
for(int i=0;i<n-1;i++)
{
scanf("%d",&a[i]);
sum+=a[i];
}
int total=n*(n+1)/2;
printf("missing element are:%d",total-sum);
}
/*
//for multiple missing elements;
#include <stdio.h>
int main() {
int n;
scanf("%d", &n);
int a[n]; // Input array
int freq[n + 1]; // Frequency array to track presence
// Initialize frequency array
for (int i = 0; i <= n; i++) {
freq[i] = 0;
}
// Read input and mark presence
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
if (a[i] >= 1 && a[i] <= n) {
freq[a[i]]++;
}
}
// Print missing numbers
printf("Missing numbers are: ");
for (int i = 1; i <= n; i++) {
if (freq[i] == 0) {
printf("%d ", i);
}
}
printf("\n");
return 0;
}*/