Skip to content

CGreenP/NPTEL-Introduction-to-Programming-in-C-Assignment-3-Question-1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

NPTEL-Introduction-to-Programming-in-C-Assignment-3-Question-1

NPTEL Introduction to Programming in C Assignment 3 Question 1

Question 1

Write a C function to find the kth occurrence of an even integer in a sequence of non-negative integers, and then call your function from main.

Your function should be according to the following declaration:

int find_even(int k);

Input

You are given the input in two lines:

The first line contains a positive integer k. In the second line, you will be given a sequence of numbers.

You have to find the kth occurrence of n in the sequence below.

The second line consists of a sequence of non-negative integers, terminated with a -1. The -1 is not part of the sequence.

Output

If there are k even numbers in the sequence, then output the kth occurrence of even in the sequence. Otherwise, output a -1.

Sample Input

2
1 1 3 2 3 4 1 -1

Sample Output

4

Sample input 1

2 
1 1 2 3 3 -1

Sample output 1

-1

Sample input 2

2 
2 1 1 2 3 3 -1

Sample output 2

2

Sample input 3

1 
1 1 2 3 3 -1

Sample output 3

2

Sample input 4

10
1 1 2 3 3 -1

Sample output 4

-1

About

NPTEL Introduction to Programming in C Assignment 3 Question 1

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages