
- 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 K’th smallest element in a 2D array
Declare a 2D array −
int[] a = new int[] { 65, 45, 32, 97, 23, 75, 59 };
Let’s say you want the Kth smallest i.e, 5th smallest integer. Sort the array first −
Array.Sort(a);
To get the 5th smallest element −
a[k - 1];
Let us see the complete code −
Example
using System; using System.IO; using System.CodeDom.Compiler; namespace Program { class Demo { static void Main(string[] args) { int[] a = new int[] { 65, 45, 32, 97, 23, 75, 59 }; // kth smallest element int k = 5; Array.Sort(a); Console.WriteLine("Sorted Array..."); for (int i = 0; i < a.Length; i++) { Console.WriteLine(a[i]); } Console.Write("The " + k + "th smallest element = "); Console.WriteLine(a[k - 1]); } } }
- Related Articles
- Python program to find k'th smallest element in a 2D array
- Program to find out the k-th smallest difference between all element pairs in an array in C++
- Find k-th smallest element in given n ranges in C++
- Find k-th smallest element in BST (Order Statistics in BST) in C++
- Find K-th Smallest Pair Distance in C++
- k-th missing element in sorted array in C++
- K-th Smallest Prime Fraction in C++
- K-th smallest element after removing some integers from natural numbers in C++
- Find m-th smallest value in k sorted arrays in C++
- C# Program to find the smallest element from an array
- k-th missing element in an unsorted array in C++
- Find smallest element greater than K in Python
- K-th Smallest in Lexicographical Order in C++
- Find the k-th smallest divisor of a natural number N in C++
- Find a peak element in a 2D array in C++

Advertisements