Skip to main content

Linear Search by Using Function in C

	#include<stdio.h>
	#include<conio.h>
	#include<dos.h>

	void LINEAER_SEARCH(int DATA[50],int x);

	void TAKING_VALUE(int DATA[50],int x)
		{
		int i;
		printf("START ENTERING VALUE\n");
		for(i=1;i<=x;i++)
			{
			printf("DATA[%d]=",i);
			scanf("%d",&DATA[i]);
			}
		LINEAER_SEARCH(DATA,x);
		}

	void LINEAER_SEARCH(int DATA[50],int x)
		{
		int i,loc,v,k=0;
		printf("ENTER VALUE TO SEARCH:\t");
		scanf("%d",&v);
		for(i=1;i<=x;i++)
			{
			if(DATA[i]==v)
				{
				k=1;
				printf("%d IS AT LOCATION %d",DATA[i],i);
				break;
				}
			}
		if(k==0)
			{
			printf("\n\aSORRY. %d CANN'T FIND",v);
			}
		}

	void main()
		{
		int i,n,DATA[50];
		char c;
		clrscr();
		printf("HOW MANY ELEMENT YOU WANT:\t");
		scanf("%d",&n);
		TAKING_VALUE(DATA,n);
		getch();
		}
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 *