C Program To Find Maximum And Minimum Numbers In An Array. If you are looking for finding maximum and minimum elements of an array program, this C programming tutorial will help you to learn how to write source code for finding maximum and minimum numbers in an array.
C Program To Find Maximum And Minimum Numbers
Learn how to write a c Program to find maximum and minimum numbers in an array. Writing minimum and maximum numbers program in C can be done using various techniques but here in this program, we show how to write a c program to find maximum and minimum elements in array in a proper way. Happy coding.
C Program To Find Maximum And Minimum Elements – Source Code
You can copy paste the below C Program to find maximum and minimum numbers in an array using for loop, in c compiler to check how the source code work.
Example Source Code:
/* C program to find maximum and minimum numbers in array */ #include <stdio.h> int main() { //variable declaration int arr[100]; //array of integer type declaration int i, max, min, size; //integer variables /* Asking user to enter size of the array */ printf("Enter size of the array: "); scanf("%d", &size); //reading array size from user /* Asking user to enter array elements */ printf("Enter elements in the array: "); for(i=0; i<size; i++) { scanf("%d", &arr[i]); //reading array elements } /* Assume first element as maximum and minimum */ max = arr[0]; min = arr[0]; /* Finding maximum and minimum elements in an array */ for(i=1; i<size; i++) { /* If current element of array is greater than max */ if(arr[i]>max) { max = arr[i]; } /* If current element of array is smaller than min */ if(arr[i]<min) { min = arr[i]; } } /* Printing maximum and minimum elements of an array */ printf("Maximum element = %d\n", max); printf("Minimum element = %d", min); return 0; }
C Program To Find Maximum And Minimum Elements – Output
After you compile and run the above c program to find maximum and minimum numbers in array, your C compiler asks you to enter the array size and array elements. After entering size and elements, compiler will check for maximum and minimum numbers and display.
Output:
Enter size of the array:
Enter elements in the array: 5 10 15 -5 20
Maximum element = 20
Minimum element = -5
C PROGRAMMING EXAMPLES
- C Program to Read a Text File
- C Program to Convert Decimal to Hexadecimal
- C Program to Convert Decimal to Binary
- C Program to Convert Celsius to Fahrenheit
- C Program To Find Absolute Value
- Ternary Operator Program in C
- C Program For Addition Table Using For Loop
- Denomination Program in C
- C Program to Print Multiplication Table
- C Program Array with Example
- Binary Search in C Program Using Recursion
- Bubble Sort in C Using Pointers
- Bubble Sort Program in C Using Recursion
- Bubble Sort Program in C Using Array
- Bubble Sort Program in C Using Function
- Bubble Sort Program in C Using Linked List
- Stack Push Pop Program in C Using Arrays
- Factorial Program in C Using Pointers
- Factorial Program in C Using While Loop
- C Program For Factorial Using For Loop