B. Searching – Codeforces Problem Solution in C

Disclaimer: Make sure you tried enough before checking the solution

Problem: https://codeforces.com/group/MWSDmqGsZm/contest/219774/problem/B

#include<stdio.h>
int main() {
    int a,i,ct=0,c;
    int b[100000];
    scanf("%d",&a);
    for(i=0;i<a;i++){
        scanf("%d",&b[i]);
    }
    scanf("%d",&c);
    for(i=0;i<a;i++){
        if(c==b[i]){
            ct = 1;
            printf("%d",i);
            break;
        }
    }
    if(ct==0){
        printf("-1");
    }

    return 0;
}

Assiut University Training – Newcomers solution

Leave a Comment