Q:

Write a program in c to search an element form array by linear serach method

0

Write a program in c to search an element form array by linear serach method

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

#include<stdio.h>
#include<conio.h>
void main()
{
	int i,n,search,count=0;
	printf("\n\t Enter number of element in array");
	scanf("%d",&n);
	int arr[n];
	printf("\n\t Enter %d number",n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&arr[i]);
	}
	printf("\n\t Enter a number to search");
	scanf("%d",&search);
	for(i=0;i<n;i++)
	{
		if(arr[i]==search)
		{
			printf("\n\t  %d present at location %d",search,(i+1));
			count++;
		}
	}
	if(count==0)
	{
		printf("\n\t %d is  not present in array ",search);
	}
	else
	{
		printf("\n\t %d is present %d times in array",search,count);
		
	}
}

Output:

	 Enter number of element in array 7

	 Enter 7 number 10 12 15 76 59 45 57

	 Enter a number to search 10

	  10 present at location 1
	 10 is present 1 times in array

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C Programming Exercises With Solutions

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Write a c program to find transpose of matrix... >>
<< write program in c to calculate volume using funct...