Skip to main content

Linear Search in C

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
void main()
	{
	int i,n,DATA[50],index,v,l=1;
	char c;
	clrscr();
	printf("How many element you want :\t"); scanf("%d",&n);
	clrscr();
	printf("Start entering value:\n");
	for(i=1;i<=n;i++)
		{
		printf("DATA[%d]=",i);	scanf("%d",&DATA[i]);
		}
	printf("\nDO YOU WANT TO SEARCH ANY DATA.(y/n)");
	c=getch();
	if(c=='y')
		{
		 SEARCH:
		 printf("\nENTER VALUE TO SEARCH: ");scanf("%d",&v);
		 for(i=1;i<=n;i++)
			{
			if(DATA[i]==v)
				{
				l=0;
				index=i;
				printf("\nINDEX NUMBER OF %d IS %d",v,index);
				break;
				}
			}
		   if(l==1)
			{
			printf("\n\aSORRY THERE ISN'T SUCH KIND OF VALUE.TRY AGAIN...");
			goto SEARCH;
			}
		   printf("\nDO IT AGAIN ?(y/n)");
		   c=getch();
		   if(c=='y')
			{
			goto SEARCH;
			}

		}
	else
		exit(1);
	}
Spread the love

Mashkawat Ahsan

I am Mashkawat Ahsan. Wikipedian, Mozillian, tech activist, art lover. Thank you for visiting.

Leave a Reply

Your email address will not be published. Required fields are marked *