Skip to content

Instantly share code, notes, and snippets.

@gauteh
Created February 5, 2014 08:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gauteh/8819282 to your computer and use it in GitHub Desktop.
Save gauteh/8819282 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
class Digits {
static int get_digits (decimal d) {
if (d < 1) {
return 0;
} else {
return 1 + get_digits (d / 10);
}
}
static void Main (string [] args)
{
Console.WriteLine ("Digits: ");
/* add some test values */
List<String> test_values = new List<String> ();
test_values.Add ("999999999999998");
test_values.Add ("999999999999999");
test_values.Add ("9999999999999939");
for (int i = 0; i < args.Length; i++) {
Console.Write (args[i]);
Console.Write (": ");
decimal d = Convert.ToDecimal (args[i]);
Console.WriteLine (get_digits (d));
}
Console.WriteLine ("Predef values:");
args = test_values.ToArray();
for (int i = 0; i < args.Length; i++) {
Console.Write (args[i]);
Console.Write (": ");
decimal d = Convert.ToDecimal (args[i]);
Console.WriteLine (get_digits (d));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment