
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
C# program to find maximum and minimum element in an array
Set the minimum and maximum element to the first element so that you can compare all the elements.
For maximum.
if(arr[i]>max) { max = arr[i]; }
For minimum.
if(arr[i]<min) { min = arr[i]; }
You can try to run the following code to find maximum and minimum elements’ position.
Example
using System; public class Demo { public static void Main() { int[] arr = new int[5] {99, 95, 93, 89, 87}; int i, max, min, n; // size of the array n = 5; max = arr[0]; min = arr[0]; for(i=1; i<n; i++) { if(arr[i]>max) { max = arr[i]; } if(arr[i]<min) { min = arr[i]; } } Console.Write("Maximum element = {0}
", max); Console.Write("Minimum element = {0}
", min); } }
Output
Maximum element = 99 Minimum element = 87
- Related Articles
- Program to find the minimum (or maximum) element of an array in C++
- PHP program to find the minimum element in an array
- How to find the minimum and maximum element of an Array using STL in C++?
- PHP program to find the maximum element in an array
- C Program to Minimum and Maximum prime numbers in an array
- C++ Program to Find Minimum Element in an Array using Linear Search
- C++ program to rearrange an array in maximum minimum form
- C++ Program to Find Maximum Element in an Array using Binary Search
- Program to find maximum XOR with an element from array in Python
- Write a Golang program to find the element with the minimum value in an array
- C++ Program to Find the Minimum element of an Array using Binary Search approach
- Program to find number of sublists containing maximum and minimum after deleting only one element in Python
- Recursive program to find an element in an array linearly.
- Maximum and minimum of an array using minimum number of comparisons in C
- Python Program to find largest element in an array

Advertisements