C program to search the number from array with its position

In these program we will learn how to write a C program to search the number from array with its position.


EX: Write a C program to search the number from array with its position. How to write a C program to search the element from array elements. C program to search the number from array with its position.



  Program to search the number from array with its position :


#include<stdio.h>
void main()
{
 int a[100];
 int i,lim,f=0,num;
 printf("Enter the limit: \n");
 scanf("%d",&lim);
 printf("Enter the elements: \n");
 for(i=0;i<lim;i++)
 {
  scanf("%d",&a[i]);   
 }
 printf("Enter the number which you want to search: \n");
 scanf("%d",&num);
 for(i=0;i<lim;i++)
 {
  if(a[i]==num)
  { 
  printf("Number found at position: %d\n",i+1);
  f++;
  }
 
 }
 if(f==0)
 printf("Number not found :(");

}



Above program will show the following output:

Output 1:

Enter the limit: 8

Enter the elements:
4
5
2
3
6
8
2


Enter the number which you want to search: 2

Number found at position: 1
Number found at position: 4
Number found at position: 8



Output 2:

Enter the limit: 5

Enter the elements:
1
3
4
5
2

Enter the number which you want to search: 7

Number not found :(




No comments:

Post a Comment

If you have any doubts, please discuss here...👇