Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
451 B
1
Indexable
Never
public static int calc_sum(int number)
 {
 int sum = 0, reminder;
 while (number > 0)
 {
 reminder = number % 10;
 sum = sum + reminder;
 number = number / 10;
 }
 return sum;
 }
 static void Main(string[] args)
 {
 int number,sum;
 Console.Write("Enter a number: ");
 number = int.Parse(Console.ReadLine());
 sum = calc_sum(number);
 Console.WriteLine("The sum of the digits of the number {0} is : {1} \n", 
number, sum);
 }
 }
}
Leave a Comment