Q:

Ascending Order Program using C# Language

0

This Program is used to arrange the elements in ascending Order

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

using System;

public class exam
{
public static void Main()
{
int[] a = {5,3,1,7,2};
int i,j,t;

Console.WriteLine("The given values are..."); 
for(i=0;i<5;i++)
{
Console.Write("{0}\t",a[i]);
}

for(i=0;i<5;i++)
{
for(j=i+1;j<5;j++)
{
if(a[i] > a[j])
{
t = a[i];
a[i] = a[j];
a[j] = t;
}
}
}
Console.WriteLine("\n");
Console.WriteLine("The Ascending Order values are..."); 
for(i=0;i<5;i++)
{
Console.Write("{0}\t",a[i]);
}

}
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now