My Profile

I, Das ShrikKrishna J. MCA III IMSCD&R, Ahmednagar.

Monday, 15 August 2011

Search an Element using Linear Search (Iteration)

Write a Program in C to Search an Element in the Array using Linear Search (Iteration)
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],i,num,flag=0;
clrscr();
printf("Enter 5 numbers\n");
for(i=0;i<=4;i++)
{
scanf("%d", &a[i]);
}
printf("\nEnter the number to be searched\n");
scanf("%d",&num);
for(i=0;i<=4;i++)
{
if(a[i]==num)
{
flag=1;
printf("Number (%d) found at position (%d)\n",num,i+1);
break;
}
}
if(flag==0)
{
printf("\nDidnot find the number (%d)\n",num);
}
getch();
}

No comments:

Post a Comment

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | cheap international calls