EXP1DDA

🧩 Syntax:
#include <stdio.h>

/*

 * Part of Cosmos by OpenGenus Foundation

 * Input: an integer array with size in index 0, the element to be searched

 * Output: if found, returns the index of the element else -1

*/

int search(int arr[], int size, int x)

{

    for (int i = 0; i < size; i++)

        if (arr[i] == x)

            return i;

    return -1;

}

int main()

{

    int size, find;

    

    printf("Enter the size of the array: ");

    scanf("%d", &size);

    

    int arr[size];

    printf("Enter %d elements: ", size);

    for (int i = 0; i < size; i++)

    {

        scanf("%d", &arr[i]);

    }

    

    printf("Enter the element to be searched: ");

    scanf("%d", &find);

    int position = search(arr, size, find);

    if (position != -1)

        printf("Position of %d is %d\n", find, position);

    else

        printf("%d is not found in the array\n", find);

    

    printf("Name: Siddharth Shinde\n");

    printf("Roll no: 22141274\n");

    return 0;

}