How to print digit segmentation of a number in C#

1 Answer

0 votes
using System;

public class DigitSegmentation
{
    public static void Main(string[] args)
    {
        int n = 873921779, tmp = n;
        int[] arr = new int[10];
 
        while (tmp != 0) {
            arr[tmp % 10]++;
            tmp = tmp / 10;
        }
        
        Console.WriteLine(n);
        
        for (int i = 0; i < arr.Length; i++) {
            Console.WriteLine("{0} {1}", i, arr[i]);
        }
    }
}



/*
run:

873921779
0 0
1 1
2 1
3 1
4 0
5 0
6 0
7 3
8 1
9 2

*/


answered Apr 10, 2014 by avibootz
edited Jan 18, 2025 by avibootz
...