Write a C# Sharp program to sort a given positive number in descending/ascending order
- برمجة سي شارب
- برمجة
- 2021-05-31
- ahmadghneem
الأجوبة
using System;
using System.Linq;
namespace exercises
{
class Program
{
static void Main(string[] args)
{
int n = 134543;
Console.WriteLine("Original Number: " + n);
Console.WriteLine("\nDescending order of the said number: " + test_dsc(n));
Console.WriteLine("\nAscending order of the said number: " + test_asc(n));
n = 4375973;
Console.WriteLine("\nOriginal Number: " + n);
Console.WriteLine("\nDescending order of the said number: " + test_dsc(n));
Console.WriteLine("\nAscending order of the said number: " + test_asc(n));
}
public static int test_dsc(int num)
{
return Convert.ToInt32(String.Concat(num.ToString().OrderByDescending(x => x)));
}
public static int test_asc(int num)
{
return Convert.ToInt32(String.Concat(num.ToString().OrderBy(x => x)));
}
}
}
أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال