fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. const int SIZE = 50;
  6. float A[SIZE];
  7.  
  8. float *ptr = A; // pointer to the array
  9.  
  10. // ---- Input 50 float numbers ----
  11. cout << "Enter 50 float numbers:\n";
  12. for (int i = 0; i < SIZE; i++) {
  13. cin >> *(ptr + i);
  14. }
  15.  
  16. // ---- Input number x to search ----
  17. float x;
  18. cout << "\nEnter number to search for: ";
  19. cin >> x;
  20.  
  21. // ---- Search for x using pointer ----
  22. float *foundAddress = nullptr;
  23.  
  24. for (int i = 0; i < SIZE; i++) {
  25. if (*(ptr + i) == x) {
  26. foundAddress = (ptr + i);
  27. break;
  28. }
  29. }
  30.  
  31. // ---- Print result ----
  32. if (foundAddress != nullptr) {
  33. cout << "\nNumber found at address: " << foundAddress << endl;
  34. } else {
  35. cout << "\nNumber NOT found in the array." << endl;
  36. }
  37.  
  38. return 0;
  39. }
  40.  
Success #stdin #stdout 0.01s 5276KB
stdin
Standard input is empty
stdout
Enter 50 float numbers:

Enter number to search for: 
Number found at address: 0x7ffc78f650d4