Code to search location of element in array

Code to search location of element in array

#include<stdio.h>
#include<conio.h>
void main()
{
    int i,a[5],b,c=0;
    printf("Enter 3 elements");
    for(i=0;i<3;i++)
    {
        scanf("%d",&a[i]);
    }
    printf("Enter number that you want to search");
    scanf("%d",&b);
    for(i=0;i<3;i++)
    {
     if(b==a[i])
     {
      c=1;
      printf("Element found at location(location will start from 0)= %d",i);
     }
    }
    if(c==0)
    {
        printf("Element not found");
    }
    getch();
    }

Output



Comments

Popular posts from this blog

Code for pattern 6

Code to check leap year