Number to integer array
Write a program to accept the number and returns a list of its digits.
For example
Input
10391990
Output:
[1, 0, 3, 9, 1, 9, 9, 0]
Solution:
using System;
using System.Collections.Generic;
namespace IntegerArray
{
class Program
{
static void Main()
{
Console.WriteLine("Enter a number");
var num = Convert.ToInt32(Console.ReadLine());
var temp = num;
var arr = new List<int>();
do
{
arr.Add(temp % 10);
temp /= 10;
} while (temp > 0);
Console.WriteLine("Array after sorting");
foreach (var t in arr)
Console.WriteLine(t);
Console.ReadLine();
}
}
}