Skip to content

Commit c3af0a1

Browse files
authored
Create Find me.c
1 parent d1de901 commit c3af0a1

File tree

1 file changed

+51
-0
lines changed
  • Codechef Problems/DSA Learning Series

1 file changed

+51
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/* You are given a list of N integers and a value K. Print 1 if K exists in the given list of N integers, otherwise print −1.
2+
3+
Input:
4+
First-line will contain two numbers N and K.
5+
Next line contains N space-separated numbers.
6+
Output:
7+
Print the answer in a new line.
8+
9+
Constraints
10+
1≤N,K,Ai≤105
11+
Sample Input 1:
12+
4 2
13+
1 2 3 4
14+
Sample Output 1:
15+
1
16+
Sample Input 2:
17+
4 4
18+
1 2 6 9
19+
Sample Output 2:
20+
-1
21+
EXPLANATION:
22+
In the first example, as 2 is present in the list.
23+
In the second example, 4 is not present in the list. */
24+
25+
#include <stdio.h>
26+
27+
int main(void) {
28+
29+
int n,k;
30+
scanf("%d %d",&n,&k);
31+
int a[n];
32+
int c=0;
33+
for(int i=1; i<=n; i++)
34+
{
35+
scanf("%d ",&a[i]);
36+
if(a[i]==k)
37+
{
38+
c=1;
39+
}
40+
}
41+
42+
if(c==1)
43+
{
44+
printf("1");
45+
}
46+
else
47+
{
48+
printf("-1");
49+
}
50+
return 0;
51+
}

0 commit comments

Comments
 (0)