C Program
#include<stdio.h> int main() { int a[100], n, x, i; scanf("%d%d", &n, &x); for(i = 0; i < n; i++) scanf("%d", &a[i]); for(i = 0; i < n && a[i] != x; i++); printf(i < n ? "Found at %d" : "Not Found", i); }
C Output
Input: 5 12 3 7 12 9 5 Output: Found at 2
C++ Program
#include<iostream> using namespace std; int main() { int a[100], n, x, i; cin >> n >> x; for(i = 0; i < n; i++) cin >> a[i]; for(i = 0; i < n && a[i] != x; i++); cout << (i < n ? "Found at " + to_string(i) : "Not Found"); }
C++ Output
Input: 4 8 1 2 3 8 Output: Found at 3
JAVA Program
import java.util.*; class L { public static void main(String[] a) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(), x = sc.nextInt(), i; int[] arr = new int[n]; for(i = 0; i < n; i++) arr[i] = sc.nextInt(); for(i = 0; i < n && arr[i] != x; i++); System.out.print(i < n ? "Found at " + i : "Not Found"); } }
JAVA Output
Input: 6 10 4 5 10 23 42 11 Output: Found at 2
Python Program
n, x = map(int, input().split()) a = list(map(int, input().split())) print(f"Found at {a.index(x)}" if x in a else "Not Found")
Python Output
Input: 5 7 2 4 6 7 9 Output: Found at 3
In-Depth Learning – Entire Concept in Paragraphs
Social Plugin