fork download
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4. // your code goes here
  5. int a[50],limit,i,search,flag=0,pos=0;
  6. char ch;
  7. ch='y';
  8.  
  9.  
  10. do{
  11. printf("Enter a limit for array : ");
  12. scanf("%d",&limit);
  13. printf("Enter Elements : ");
  14. for(i=0;i<limit;i++)
  15. {
  16. scanf("%d",&a[i]);
  17. }
  18. printf("Enter a Number to be searched : ");
  19. scanf("%d",&search);
  20. for(i=0;i<limit;i++)
  21. {
  22. if(search==a[i])
  23. {
  24. flag=1;
  25. pos=i+1;
  26. break;
  27. }
  28. }
  29. if(flag==0)
  30. printf("search not found");
  31. else if(flag==1)
  32. printf("search found at %d position\n",pos);
  33. printf("DO YOU WANT TO REPEAT?\ny or n");
  34. scanf("%c",&ch);
  35.  
  36. }while(ch=='y');
  37.  
  38.  
  39. return 0;
  40. }
  41.  
Success #stdin #stdout 0s 2172KB
stdin
3
11
22
33
22
y
stdout
Enter a limit for array : Enter Elements : Enter a Number to be searched : search found at 2 position
DO YOU WANT TO REPEAT?
y or n