C Program To Find Maximum And Minimum Numbers In An Array

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

  1. C Program to Read a Text File
  2. C Program to Convert Decimal to Hexadecimal
  3. C Program to Convert Decimal to Binary
  4. C Program to Convert Celsius to Fahrenheit
  5. C Program To Find Absolute Value
  6. Ternary Operator Program in C
  7. C Program For Addition Table Using For Loop
  8. Denomination Program in C
  9. C Program to Print Multiplication Table 
  10. C Program Array with Example
  11. Binary Search in C Program Using Recursion
  12. Bubble Sort in C Using Pointers
  13. Bubble Sort Program in C Using Recursion
  14. Bubble Sort Program in C Using Array
  15. Bubble Sort Program in C Using Function
  16. Bubble Sort Program in C Using Linked List
  17. Stack Push Pop Program in C Using Arrays
  18. Factorial Program in C Using Pointers
  19. Factorial Program in C Using While Loop
  20. C Program For Factorial Using For Loop

Leave a Comment