0
How we solve this problem? (Help )
Enter a number to search:12 Found Enter a number to search:11 Not found Program: #include <stdio.h> int main() { int a[10]; int k; for (int i = 0; i < 10; i++) a[i] = i*2; for (int j = 0; j < 10; j++) printf("a[%d]= %d\n", j, a[j]); printf("Enter a number to search\n"); scanf_s("%d", &k); for (int x = 0; x < 10; x++) { if (k == a[x]) printf("Found"); else printf("Not found"); } return 0; }
3 Réponses
+ 4
Looks like you used a word processor to code or copy pasted this code from somewhere.
Because there are a lot of non printable characters in your code which were added by word processor to format it
0
You can solve it with linear or binary search... If you found the desired number, print found, break the loop, if it's not found (usually -1), print not found.