Advertisement
Anonymous0069

Min number in an Array

Jun 19th, 2025 (edited)
425
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | Source Code | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5.     int size;
  6.     cout << "Enter the number of numbers you want to enter: ";
  7.     cin >> size;
  8.  
  9.     int num[size];
  10.     cout << "Enter the numbers: ";
  11.  
  12.     for (int i = 0; i < size; i++) {
  13.         cin >> num[i];
  14.     }
  15.  
  16.     int minNum = num[0];  // assume first is minimum
  17.  
  18.     for (int i = 1; i < size; i++) {
  19.         if (num[i] < minNum) {
  20.             minNum = num[i];
  21.         }
  22.     }
  23.  
  24.     cout << "The minimum number is: " << minNum << endl;
  25.  
  26.     return 0;
  27. }
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement