ascending The Elements of The Array: Console Console
ascending The Elements of The Array: Console Console
{
//Sum of all elements in an array
int[] array=new int []{2,2,2,2};
int sum1 = array.Sum();
Console.WriteLine("The sum is: {0}", sum1);
Console.ReadLine();
}
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int[] a = new int[5];
int tmp, j;
Console.WriteLine("Enter the element of the array:");
for (int i = 0; i < a.Length; i++)
{
Console.Write("Element {0};",i);
a[i] = Convert.ToInt32(Console.ReadLine());
}
for (int i = 0; i < a.Length; i++)
{
for ( j = i + 1; j < a.Length; j++)
{
if (a[j] < a[i])
{
tmp = a[i];
a[i] = a[j];
a[j] = tmp;
}
}
}
Console.WriteLine("{0} {1} {2} {3} {4}", a[0],
a[1],a[2],a[3],a[4]);
Console.ReadLine();
}
}
}