Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- search_element_in_array.c
- You can find all my C programs at Dragan Milicev's pastebin:
- https://pastebin.com/u/dmilicev
- */
- #include <stdio.h>
- int main(void)
- {
- int i, value, n=10;
- int a[10]={12,23,34,45,56,67,36,44,11,100};
- printf("\n Array is: \n");
- for(i=0; i<n; i++)
- printf("\n a[%d] = %3d ",i,a[i]);
- printf("\n\n Enter value to search: ");
- scanf("%d", &value);
- i=0;
- while( a[i] != value && i < n ){
- printf("\n a[%d] = %d ",i,a[i]);
- i++;
- }
- (i<n) ? printf("\n a[%d] = %d ",i,a[i]) : printf("\n");
- (i==n) ? printf("\n\n Couldn't find value %d \n",value) : printf("\n\n Entered value %d has index %d \n",value,i);
- /*
- if(i==n)
- printf("\n\n Couldn't find value %d \n",value);
- else
- printf("\n\n Entered value %d has index %d \n",value,i);
- */
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement