Write a program to implement sequential search algorithm.

This answer is restricted. Please login to view the answer of this question.

Login Now

Program to implement sequential search:

#include <stdio.h>

int main(){
    int size, i, search, found=0;
    printf("Enter size of Array: ");
    scanf("%d", &size);

    int data[size];
    printf("Enter %d numbers in Array: ", size);
    for(i=0; i < size; i++){
        scanf("%d", &data[i]);
    }

    printf("Enter the number to be search:");
    scanf("%d", &search);
    
    for (i = 0; i < size; i++){
        if( data[i] == search ){
            printf("%d found in Array in index %d", search, i);
            found = 1;
            break;
        }
    }

    if( ! found ){
        printf("The number is not in Array.\n");
    }
    return 0;
}

The output of above program is:

Enter size of Array: 5
Enter 5 numbers in Array: 10
12
13
14
15
Enter the number to be search:12
12 found in Array in index 1
If you found any type of error on the answer then please mention on the comment or report an answer or submit your new answer.
Leave your Answer:

Click here to submit your answer.

Discussion
0 Comments
  Loading . . .