Program to find any number from array and print its position


#include<stdio.h>
main ()
{
     int a[100],item,num,i;
     printf("Enter the number of element for array : ");
     scanf("%d",&num);
     printf("Enter the array elements (%d) for array : \n",num);
     for(i=0;i<num;i++)
     {
        scanf("%d",&a[i]);
     }
     printf("Enter the item you want to search : ");
     scanf("%d",&item);
//start searching
     for(i=0;i<num;i++)
     if(item==a[i])
     {
        printf("\nItem %d is found at the position %d",item,i+1);
     }
     if(item!=a[i])
     {
        printf("\nItem not found.");
     }
getch();
}

Comments

Popular posts from this blog

Migrating database from ASP.NET Identity to ASP.NET Core Identity

Customize User's Profile in ASP.NET Identity System

Lambda two tables and three tables inner join code samples