"c# square every digit of a number" Code Answer's
You're definitely familiar with the best coding language C# that developers use to develop their projects and they get all their queries like "c# square every digit of a number" answered properly. Developers are finding an appropriate answer about c# square every digit of a number related to the C# coding language. By visiting this online portal developers get answers concerning C# codes question like c# square every digit of a number. Enter your desired code related query in the search bar and get every piece of information about C# code related question on c# square every digit of a number.
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()));
}
All those coders who are working on the C# based application and are stuck on c# square every digit of a number can get a collection of related answers to their query. Programmers need to enter their query on c# square every digit of a number related to C# code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about c# square every digit of a number for the programmers working on C# code while coding their module. Coders are also allowed to rectify already present answers of c# square every digit of a number while working on the C# language code. Developers can add up suggestions if they deem fit any other answer relating to "c# square every digit of a number". Visit this developer's friendly online web community, CodeProZone, and get your queries like c# square every digit of a number resolved professionally and stay updated to the latest C# updates.