The following Program is a Example of getting 10 integer numbers (from -1000 to 1000) from User and Store it in an array and sort them and Display. .
WITH .NET Feature :
WITH .NET Feature :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
String num_str;
int[] num = new int[10];
int temp;
bool num_flag = false;
Console.WriteLine("Enter 10 integer number:");
for(int i = 0 ; i < 10 ; i++)
{
Console.WriteLine("enter {0} number",i);
num_str = Console.ReadLine();
num_flag = int.TryParse(num_str, out temp);
while (num_flag == false)
{
Console.WriteLine("please Enter interger");
num_str = Console.ReadLine();
num_flag = int.TryParse(num_str, out temp);
}
if ((temp >= -1000) && (temp <= 1000))
{
num[i] = temp;
}
else
{
Console.WriteLine("Please Enter number (-1000 <= x <= 1000");
i--;
}
}
Array.Sort(num);
foreach (int value in num)
{
Console.Write(value);
Console.Write(' ');
}
Console.ReadLine();
}
}
}
WITHOUT .NET Feature :
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
String num_str;
int[] num = new int[10];
int temp;
bool num_flag = false;
Console.WriteLine("Enter 10 integer number:");
for(int i = 0 ; i < 10 ; i++)
{
Console.WriteLine("enter {0} number",i);
num_str = Console.ReadLine();
num_flag = int.TryParse(num_str, out temp);
while (num_flag == false)
{
Console.WriteLine("please Enter interger");
num_str = Console.ReadLine();
num_flag = int.TryParse(num_str, out temp);
}
if ((temp >= -1000) && (temp <= 1000))
{
num[i] = temp;
}
else
{
Console.WriteLine("Please Enter number (-1000 <= x <= 1000");
i--;
}
}
Array.Sort(num);
foreach (int value in num)
{
Console.Write(value);
Console.Write(' ');
}
Console.ReadLine();
}
}
}
WITHOUT .NET Feature :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
String num_str;
int[] num = new int[10];
int temp;
bool num_flag = false;
Console.WriteLine("Enter 10 integer number:");
for(int i = 0 ; i < 10 ; i++)
{
Console.WriteLine("enter {0} number",i);
num_str = Console.ReadLine();
num_flag = int.TryParse(num_str, out temp);
while (num_flag == false)
{
Console.WriteLine("please Enter interger");
num_str = Console.ReadLine();
num_flag = int.TryParse(num_str, out temp);
}
if ((temp >= -1000) && (temp <= 1000))
{
num[i] = temp;
}
else
{
Console.WriteLine("Please Enter number (-1000 <= x <= 1000");
i--;
}
}
//Array.Sort(num);
for (int x = 0; x < num.Length; x++)
{
for (int y = 0; y < num.Length - 1; y++)
{
if (num[y] > num[y + 1])
{
int temp1 = num[y + 1];
num[y + 1] = num[y];
num[y] = temp1;
}
}
}
foreach (int value in num)
{
Console.Write(value);
Console.Write(' ');
}
Console.ReadLine();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
String num_str;
int[] num = new int[10];
int temp;
bool num_flag = false;
Console.WriteLine("Enter 10 integer number:");
for(int i = 0 ; i < 10 ; i++)
{
Console.WriteLine("enter {0} number",i);
num_str = Console.ReadLine();
num_flag = int.TryParse(num_str, out temp);
while (num_flag == false)
{
Console.WriteLine("please Enter interger");
num_str = Console.ReadLine();
num_flag = int.TryParse(num_str, out temp);
}
if ((temp >= -1000) && (temp <= 1000))
{
num[i] = temp;
}
else
{
Console.WriteLine("Please Enter number (-1000 <= x <= 1000");
i--;
}
}
//Array.Sort(num);
for (int x = 0; x < num.Length; x++)
{
for (int y = 0; y < num.Length - 1; y++)
{
if (num[y] > num[y + 1])
{
int temp1 = num[y + 1];
num[y + 1] = num[y];
num[y] = temp1;
}
}
}
foreach (int value in num)
{
Console.Write(value);
Console.Write(' ');
}
Console.ReadLine();
}
}
}