Previous Next
0 / 21
Module DEMO-32-106DEMO-C-32

Linear Search

DEMO-C-32 โ€ข Programming in C

Browser-only practice

Problem Statement

Write a C program to perform a linear search on a 1D array. Input the size n, the array elements, and a target value key. If the key is present, print "FOUND at index i" (where i is the 0-based index of the first occurrence). If not found, print "NOT FOUND".

Example 1

Input:

5 10 20 30 40 50 30

Output:

FOUND at index 2

Example 2

Input:

5 10 20 30 40 50 99

Output:

NOT FOUND

Constraints

1 <= n <= 100

Input Format

n, array, key

Output Format

Search result string

Sample Testcases

Submit runs every public testcase in this browser. Results and code never leave this device.

Sample #1
Public sample
5
10 20 30 40 50
30
FOUND at index 2
30 is at index 2.
Sample #2
Public sample
5
10 20 30 40 50
99
NOT FOUND
99 is not in the list.
Sample #3
Public sample
6
5 10 5 20 5 30
5
FOUND at index 0
First occurrence of 5 is at index 0.

Web terminal

C, C++, Java, and Python run locally in a browser VM. No worker or visualizer is used.

Saved in this browser
Editor settings