C-Program to Search in an Array

#include <stdio.h>
int main()
	int array[100], search, c, n;
	printf("Enter the number of elements in array\n");
	scanf("%d", &n);
	printf("Enter %d integer(s)\n", n);
	for (c = 0; c < n; c++)
		scanf("%d", &array[c]);
	printf("Enter the number to search\n");
	scanf("%d", &search);
	for (c = 0; c < n; c++)
		if (array[c] == search)     /* if required element found */
			printf("%d is present at location %d.\n", search, c + 1);
	if (c == n)
		printf("%d is not present in array.\n", search);
	return 0;


Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s