How to write a c program to search a number in c programming ?
Solution:
#include <stdio.h>
int main()
{
int a[100];
int n, i, m;
int position;
printf("How many numbers?\n");
scanf("%d", &n);
for(i = 0; i < n; i++)
{
printf("Enter number %d: ", i+1);
scanf("%d", &a[i]);
}
printf("Enter the number you want to search: ");
scanf("%d", &m);
for(i = 0; i < n; i++)
if(a[i] == m)
{
position = i;
break;
}
if(position == n)
printf("Number not found\n");
else
printf("%d found at position %d\n", m, position);
return 0;
}