Find Minimum Element in Array
C++
Easy
8 views
Problem Description
Description: Create a program to find the smallest number in an array. This teaches comparison logic and how to track minimum values.
Logic: Assume first element is minimum, then compare with rest
Official Solution
void question2_find_minimum() {
int numbers[] = {45, 12, 67, 23, 89, 5, 34};
int size = 7;
int minimum = numbers[0];
for(int i = 1; i < size; i++) {
if(numbers[i] < minimum) {
minimum = numbers[i];
}
}
cout << "Minimum element: " << minimum << endl;
}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!