Searching for a Value in an array in c programming

Searching for a Value in an array in c programming

#include<stdio.h>
int main()
{
    int num[]={12,34,56,78,19};
    int pos=-1,value,i;
    scanf("%d",&value);
    for(i=0;i<5;i++)
    {
        if(value==num[i]){
            pos=i+1;
            break;
        }
    }
    if(pos==-1){
        printf("value is not common");
    }
    else printf("value %d is found at %d position",value,pos);
}
INPUT: 78

OUTPUT:  value 78 is found at 4 positio

A fundamental task in programming is finding a value in an array, and the for loop is a popular iteration method.

Factorial Program in C || What is the factorial of 100 in C

Leave a Comment