Wednesday, 29 October 2014

Search element in array?

Search element in array?

#include<stdio.h>
#include<conio.h>

int main() {
   int a[30], ele, num, i;

   printf("\nEnter no of elements :");
   scanf("%d", &num);

   printf("\nEnter the values :");
   for (i = 0; i < num; i++) {
      scanf("%d", &a[i]);
   }

   printf("\nEnter the elements to be searched :");
   scanf("%d", &ele);


   i = 0;
   while (i < num && ele != a[i]) {
      i++;
   }


   if (i < num) {
      printf("Number found at the location = %d", i + 1);
   } else {
      printf("Number not found");
   }
  getch();
   return (0);
 
}
//============================== output after run on DEV C++ compiler




 

No comments:

Post a Comment

Note: only a member of this blog may post a comment.