-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubarray.c
More file actions
93 lines (69 loc) · 1.51 KB
/
Copy pathsubarray.c
File metadata and controls
93 lines (69 loc) · 1.51 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/* Problem statement *
Given an array of size n-1 and given that there are numbers from 1 to n with one missing, the missing number is to be found.
Input:
The first line of input contains an integer T denoting the number of test cases.
The first line of each test case is N.
The second line of each test case contains N-1 input C[i],numbers in array.
Output:
Print the missing number in array.
Constraints:
1 . T . 200
1 . N . 1000
1 . C[i] . 1000
Example:
Input
2
5
1 2 3 5
10
1 2 3 4 5 6 7 8 10
Output
4
9
*/
/* --NOTE --
* Input is modified */
#include<stdio.h>
int subarray(int **ptr, int,int);
int main() {
int num_test, array_size;
int max_size;
int t_index=0;
int a_index=0;
int **ptr;
num_test=array_size=max_size=0;
max_size=1000;
printf("enter no of test cases \n");
scanf("%d",&num_test);
ptr=(int**)malloc(sizeof(int)*num_test);
while(t_index !=num_test) {
printf("enter array size \n");
scanf("%d",&array_size);
if (array_size >max_size) continue;
ptr[t_index]=(int*)malloc(sizeof(int)*array_size);
a_index=0;
printf("Enter array value \n");
while(a_index !=array_size) {
scanf("%d",&ptr[t_index][a_index]);
a_index++;
}
printf("Missing number is %d \n",subarray(ptr,array_size,t_index));
t_index++;
}
free(ptr);
}
int subarray(int** ptr,int index, int t_index) {
int peek=0;
int index1=0;
int sum=0;
while (index1<=index) {
sum+=ptr[t_index][index1];
index1++;
}
index1=0;
while(index1<=index) {
peek+=index1;
index1++;
}
return (peek-sum);
}