generate functionThu, 22 Dec 2022

write a function to receive a whole number and return the sum of its digits

public static int SumOfDigits(int a) { var sum = 0; var temp = a; while (temp > 0) { sum += temp % 10; temp /= 10; } return sum; }

Questions about programming?Chat with your personal AI assistant