fork download
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. int n;
  5.  
  6. printf("Enter the number of elements :");
  7. scanf("%d",&n);
  8.  
  9. int arr[n];
  10.  
  11. printf("Enter the elements :");
  12. for (int i=0;i<n;i++)
  13. {
  14. scanf("%d",&arr[i]);
  15. }
  16.  
  17. int key,a=0;
  18.  
  19. printf("Enter the element to be found :");
  20. scanf("%d",&key);
  21.  
  22. for (int i=0;i<n;i++)
  23. {
  24. if(arr[i]==key)
  25. {
  26. printf("Element found at index %d",i);
  27. a=1;
  28. }
  29. }
  30. if(a==0)
  31. {
  32. printf("Element not found");
  33. }
  34. return 0;
  35. }
Success #stdin #stdout 0.02s 25760KB
stdin
9
3 5 7 4 1 2 6 8 9
9
stdout
#include <stdio.h>

int main() {
    int n;
    
    printf("Enter the number of elements :");
    scanf("%d",&n);
    
    int arr[n];
    
    printf("Enter the elements :");
    for (int i=0;i<n;i++)
    {
        scanf("%d",&arr[i]);
    }
    
    int key,a=0;
    
    printf("Enter the element to be found :");
    scanf("%d",&key);
    
    for (int i=0;i<n;i++)
    {
        if(arr[i]==key)
        {
            printf("Element found at index %d",i);
            a=1;
        }
    }
    if(a==0)
    {
        printf("Element not found");
    }
    return 0;
}