TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Find The Smallest And Largest Number In C#
Vijayaragavan S
Aug 11
2016
Code
28.4
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
using
System;
class
Program
{
static
void
Main()
{
int
i;
int
[] a =
new
int
[30];
// Array Declaration in C#
Console.Write(
"Enter the Number of values to find Smallest and Largest Number: "
);
int
n = Convert.ToInt16(Console.ReadLine());
// read the string value and convert it in to integer
//Reading the values one by one
for
(i = 1; i <= n; i++)
{
Console.Write(
"Enter the No "
+ i +
":"
);
a[i] = Convert.ToInt16(Console.ReadLine());
}
for
(i = 1; i <= n; i++)
{
for
(
int
j = 1; j <= n - 1; j++)
{
if
(a[j] > a[j + 1])
{
int
temp = a[j];
a[j] = a[j + 1];
a[j + 1] = temp;
}
}
}
//Display the Smallest value
Console.WriteLine(
"The smallest Value is "
+a[1]);
//Display the Biggest Value
Console.WriteLine(
"The Largest Value is "
+ a[n]);
//Waiting for output
Console.ReadKey();
}
}
Smallest
Largest
C#
arrays
Loops