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
Post a Comment