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

Your email address will not be published. Required fields are marked *

Scroll to Top
NEW TOXIC ROCKET CYCLE DECK in Clash Royale 2023 Best Deck in Clash Royale Best Deck for Arena 8 in Clash Royale Best Hog deck for Pro players Best Clash Royale Deck