#include <stdio.h>
#include <conio.h>
void main()
{
int array[10];
int i, N, keynum, found=0;
clrscr();
printf(“Enter the value of N\n”);
scanf(“%d”,&N);
printf(“Enter the elements one by one\n”);
for(i=0; i<N ; i++)
{
scanf(“%d”,&array[i]);
}
printf(“Input array is\n”);
for(i=0; i<N ; i++)
{
printf(“%d\n”,array[i]);
}
printf(“Enter the element to be searched\n”);
scanf(“%d”, &keynum);
/* Linear search begins */
for ( i=0; i < N ; i++)
{
if( keynum == array[i] )
{
found = 1;
break;
}
}
if ( found == 1)
printf(“SUCCESSFUL SEARCH\n”);
else
printf(“Search is FAILED\n”);
} /* End of main */
/*————————————
Output
RUN 1
Enter the value of N
5
Enter the elements one by one
23
12
56
43
89
Input array is
23
12
56
43
89
Enter the element to be searched
56
SUCCESSFUL SEARCH
RUN 2
Enter the value of N
3
Enter the elements one by one
456
213
879
Input array is
456
213
879
Enter the element to be searched
1000
Search is FAILED
————————————–*/
Not Satisfied ? Just search & get the result
Related posts:
- C program to read N integers (zero, +ve and -ve) into an array A and to a) Find the sum of negative numbers b) Find the sum of positive numbers and c) Find the average of all input numbers Output the various results computed with proper headings
- C program to reverse a given integer number and check whether it is a palindrome. Output the given numbers with suitable message
- C program to check whether a given number is prime or not and output the given number with suitable message
- C program to find the number of integers divisible by 5 between the given range N1 and N2, where N1 < N2 and are integers. Also find the sum of all these integer numbers that divisible by 5 and output the computed results
- C program to find the sum of odd numbers and sum of even numbers from 1 to N. Output the computed sums on two different lines with suitable headings
