Nemo048

Untitled

Jul 17th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.45 KB | None | 0 0
  1. public static int Persistence(long n)
  2.         {
  3.             // your code
  4.             string s_n = n.ToString();
  5.             int counter = 0;
  6.  
  7.             while(s_n.Length != 1)
  8.             {
  9.                 s_n = Mult(s_n);
  10.                 counter++;
  11.             }
  12.  
  13.             return counter;
  14.         }
  15.  
  16.         public static string Mult(string number)
  17.         {
  18.             string s_mult = string.Empty;
  19.             int mult = 1;
  20.  
  21.             foreach(char n in number)
  22.             {
  23.                 mult *= int.Parse(n.ToString());
  24.             }
  25.  
  26.             s_mult = mult.ToString();
  27.  
  28.             return s_mult;
  29.         }
Advertisement
Add Comment
Please, Sign In to add comment