Saved Bookmarks
| 1. |
Write a program to accept N values in an array and search for an value accepted from user (along with its position).Suppose 1 D array is as6411131519105The value to be searched for: 11Output should be as: 11 is found @ 3 position |
|
Answer» void main () { int N, a[10], pos = -1, x = 0; cout <<” enter array size “; cin >> N; for (int i = 0; i<N; i++) cin >> a[i]; cout <<” enter value to be searched”; cin >> x; for (i = 0; i < N; i++) if (a[i] == x) { pos = i; found = 1; cout << x << “ found @ “ << i+1 << “ position”; break; } if ( found = = 0) cout << x<< “not found in array”; } |
|