fork download
  1. //name: adam alizeerj
  2. // date: april 13, 2025
  3. // purpose: this program defines a function that displays all elements in an integer array that are greater than a given number 'n'
  4.  
  5. #include <iostream>
  6. using namespace std;
  7.  
  8. void displayLargerThan(int arr[], int size, int n);
  9.  
  10. int main() {
  11. const int SIZE = 10;
  12. int numbers[SIZE] = {3, 7, 10, 2, 15, 6, 20, 1, 9, 12};
  13. int n;
  14.  
  15. cout << "Enter a number to compare against: ";
  16. cin >> n;
  17.  
  18. cout << "Numbers in the array greater than " << n << " are:\n";
  19. displayLargerThan(numbers, SIZE, n);
  20.  
  21. return 0;
  22. }
  23.  
  24. void displayLargerThan(int arr[], int size, int n) {
  25. for (int i = 0; i < size; i++) {
  26. if (arr[i] > n) {
  27. cout << arr[i] << " ";
  28. }
  29. }
  30. cout << endl;
  31. }
Success #stdin #stdout 0.01s 5268KB
stdin
Standard input is empty
stdout
Enter a number to compare against: Numbers in the array greater than 22034 are: