fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. const int SIZE = 40;
  6. int arr[SIZE];
  7.  
  8. int *ptr = arr; // pointer to the array
  9.  
  10. // ---- Input 40 values ----
  11. cout << "Enter 40 integers:\n";
  12. for (int i = 0; i < SIZE; i++) {
  13. cin >> *(ptr + i); // using pointer to store values
  14. }
  15.  
  16. // ---- Find smallest value ----
  17. int smallest = *ptr; // assume first element is smallest
  18. for (int i = 1; i < SIZE; i++) {
  19. if (*(ptr + i) < smallest) {
  20. smallest = *(ptr + i);
  21. }
  22. }
  23.  
  24. // ---- Print the array ----
  25. cout << "\nArray values:\n";
  26. for (int i = 0; i < SIZE; i++) {
  27. cout << *(ptr + i) << " ";
  28. }
  29.  
  30. // ---- Print smallest value ----
  31. cout << "\n\nSmallest value = " << smallest << endl;
  32.  
  33. return 0;
  34. }
Success #stdin #stdout 0s 5316KB
stdin
Standard input is empty
stdout
Enter 40 integers:

Array values:
1667071208 5349 1666219958 5349 1667071784 5349 1667071208 5349 1667069856 5349 1666220960 5349 1667071776 5349 1667071488 5349 1667071776 5349 1665861112 5349 72703 0 1664975112 5349 1665861264 5349 1663260577 5349 -1027477496 21922 -1027476903 21922 1 0 2 0 1119579800 32764 -1027488939 21922 

Smallest value = -1027488939