Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main() {
- int size, i, key, found = 0;
- printf("Enter the size of the array: ");
- scanf("%d", &size);
- int arr[size];
- printf("Enter the elements of the array:\n");
- for (i = 0; i < size; i++) {
- scanf("%d", &arr[i]);
- }
- printf("Enter the element to search: ");
- scanf("%d", &key);
- for (i = 0; i < size; i++) {
- if (arr[i] == key) {
- found = 1;
- break;
- }
- }
- if (found) {
- printf("Element %d found at index %d\n", key, i);
- } else {
- printf("Element %d not found in the array\n", key);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment