C Program to search a number in an array

Published on September 13, 2017 by admin

Filed under C

Last modified September 13, 2017

Print this page

rate 1 star rate 2 star rate 3 star rate 4 star rate 5 star
Your rating: none, Average: 2.4 (25 votes)

This article have been viewed 12896 times

Problem Statement

Write a program in C to search for a given number within the array.

How to search for an given number in an array ?

#include <stdio.h>
int main()
   int arr[250], search, n, i;
   printf("Enter the number is elements in the array\n");
   printf("\nEnter %d number one by one", n);
   for (i = 0; i < n; i++)
      scanf("%d", &arr[i]);
   printf("\nEnter the number to search");
   scanf("%d", &search);
   for (i = 0; i < n; i++)
      if (arr[i] == search)  
         printf("\n%d is found at index %d\n", search, i+1);
   if (i == n)
      printf("%d is not found in the array.\n", search);
   return 0;

Leave a Comment


You might be Interested in these Posts

C Program to convert lower case string to upper case

Problem Statement Write a program in C to convert the given string from lower case to upper case. ...

How to decode a base64 string in C#?

Here's a sample code snippet demonstrating how you can easily decode a base64 encoded string in C#. ...

How to disable editing of items in a combo box in c#?

When working in Win forms using C# and especially when you use the combo box , you would have notice...