|
|
Write a program to create a 10 element array of
|
|
#include <stdio.h> int main(void) { int arr[10], i, val, n; printf("\nEnter ten integer values : "); for(i = 0 ; i < 10 ; i++ ) scanf("%d", &arr[i]); printf("\nEnter value to search : "); scanf("%d", &val); /* Search the value in the array */ n = 0; for(i = 0 ; i < 10 ; i++) { n++; if(arr[i] == val) break; } if(i == 10) { printf("\n%d not found in the array", val); printf("\nNo of attempts = %d", n); } else { printf("\n%d found in the array", val); printf("\nNo of attempts = %d", n); } return 0; }
|
|
|
|
|
|
|
|