Hi friends,Good Evening.
how to display numbers in ascending order in a given integer number.
input : int number=4657
output should be : 4567
please give your solutions.
Thanks
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Pankaj Kumar ChoudharyPosted Jun 13, 2015, 11:18 AM
int I = 0;
Console.WriteLine("Enter Your Number");
int.TryParse(Console.ReadLine(), out Num);
Loc=Num;
int [] Arr=new int [Loc.ToString().Length];
while (Loc != 0)
{
Arr[I] = Loc % 10;
Loc = Loc / 10;
I++;
}
Array.Sort(Arr);
Num = 0;
for (int i = 0; i < Arr.Length; i++)
{
Num += Arr[i] * Convert.ToInt32(Math.Pow(10, Arr.Length - i - 1));
}
Console.WriteLine(Num.ToString());
Console.ReadLine();