Sort the digits **programming exercise**.

*The winter is coming, and all the warehouses are nicely packed with food. But someone needs to sort it all. So the king offers a noble title to anyone who can:*

Write a function that takes an integer as an input. And then generates a new number where all the digits are sorted in an descending order.

Example: 1342 => 4321 5791 => 9751

Scroll down for the solution of this programming exercise.

public static int SortDigits(int num) {//Oh boy.. We can solve thiscoding problem//in a 1000 different ways. But since the goal is //tolearnnew things, I am going to use a lot of //functionsandexplainthem. //first letsconvert "num"tostringand then tochar array.char[] digits = num.ToString().ToCharArray();//we needed this array so we cansort it.Array.Sort(digits);//but we need areversesortingArray.Reverse(digits);//now we have achar array, but we need anintegerstring str = new string(digits);return int.Parse(str);//and that's how we convertchar arrayto astring//I want to stress that we cannot use=operator //we cannot do "str=digits". Because they aredifferent//typessis a string anddigitsis anarray. //Do be safe, assume that we can use theAssignment operator"=" //only on thesame data types.}