‘C’ program to search for a specific number in array.
C File =>
/* Write a ‘C’ program to accept n integers in an array and search for a specific number. */
#include<stdio.h>
int main()
{
int n,i,key,arr[30],flag=0;
printf("\n How many integers? ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\n Enter element%d",i+1);
scanf("%d",&arr[i]);
}
printf("\n Enter element to search : ");
scanf("%d",&key);
// Searching for key
for(i=0;i<n;i++)
{
if(arr[i]==key)
{
flag=1;
break;
}
}
if(flag==1)
printf("\n %d is found in array",key);
else
printf("\n %d is Not found in array",key);
return 0;
}
Comments
Post a Comment
Please do not enter any spam link in message.