Introduction:
Finding the maximum and minimum number from a set of values is one of the most common beginner-level programming problems. This tutorial explains how to write a C program to find maximum and minimum from 10 numbers using loops and conditional checks.
This is an essential concept that helps build skills in loops, conditionals, arrays, and logic.
Problem Statement:
Write a C program that:
- Takes 10 numbers as input from the user.
- Identifies and displays the maximum and minimum values from the entered numbers.
C Program Code:
#include <stdio.h>
int main() {
int numbers[10], i;
int max, min;
// Input 10 numbers from user
printf("Enter 10 numbers:\n");
for (i = 0; i < 10; i++) {
scanf("%d", &numbers[i]);
}
// Initialize max and min with first number
max = min = numbers[0];
// Compare each number with current max and min
for (i = 1; i < 10; i++) {
if (numbers[i] > max) {
max = numbers[i];
}
if (numbers[i] < min) {
min = numbers[i];
}
}
// Display results
printf("Maximum number is: %d\n", max);
printf("Minimum number is: %d\n", min);
return 0;
}
Explanation of the Code:
- An array of size 10 is used to store user input.
- We initialize both
max
andmin
with the first number. - The program then loops through the rest of the array, updating
max
andmin
as it finds higher or lower values. - Finally, it prints the maximum and minimum values.
Why It Matters:
- Teaches basic looping and array traversal
- Enhances understanding of comparative logic
- Common use case in real-world data analysis or search operations
Where This Logic Is Used:
- Stock price analysis
- Performance tracking systems
- Exam result evaluation
- Any form of range or threshold calculations
Conclusion:
This program demonstrates a fundamental use case in C programming — finding maximum and minimum values from a set of inputs. It’s simple, efficient, and a great way to practice loops, conditionals, and array handling.