TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Linear Search Program In C For Multiple Occurrences
Ashish Srivastava
Aug 26
2016
Code
6.8
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
#include <stdio.h>
#include <conio.h>
void
main()
{
int
array[100], search, i, n, count = 0;
printf(
"Enter the number of elements in array\n"
);
scanf(
"%d"
, &n);
printf(
"Enter %d numbers\n"
, n);
for
( i = 0 ; i < n ; i++ )
{
scanf(
"%d"
, &array[i]);
}
printf(
"Enter the number to search\n"
);
scanf(
"%d"
, &search);
for
(i = 0; i < n; i++) {
if
(array[i] == search) {
printf(
"%d is present at location %d.\n"
, search, i+1);
count++;
}
}
if
(count == 0)
printf(
"%d is not present in array.\n"
, search);
else
printf(
"%d is present %d times in array.\n"
, search, count);
getch();
}
Linear search Program
C