Horje
c#  square every digit of a number Code Example
c# square every digit of a number
//c#  square every digit of a number 
public static int SquareDigits(int n)
        {
            var val = n.ToString();

            var result = "";

            for (var i = 0; i < val.Length; i++)
            {
                char c = val[i];
                int num = int.Parse(c.ToString());
                result += (num * num);
            }
            return int.Parse(result);
        }
  ------------------------------------------------Option 2
  public static int SquareDigits(int n)
        {
            var result =
         n
        .ToString()
        .ToCharArray()
        .Select(Char.GetNumericValue)
        .Select(a => (a * a).ToString())
        .Aggregate("", (acc, s) => acc + s);
            return int.Parse(result);
        }
-------------------------------------------------option 3
public static int SquareDigits(int n)
        {
            List<int> list = new List<int>();
            while (n != 0)
            {
                int remainder = n % 10;
                n = n / 10;
                list.Add((remainder * remainder));
            }
            return int.Parse(String.Join("", list.ToArray()));
        }




Csharp

Related
c# convert to nullable datetime Code Example c# convert to nullable datetime Code Example
c# type of string Code Example c# type of string Code Example
unity making homing missile Code Example unity making homing missile Code Example
linq select max value from list Code Example linq select max value from list Code Example
c# find element in list of list Code Example c# find element in list of list Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
11