using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WholeNumbers1
{
class Program
{
static void Main(string[] args)
{
int sum = 0;
int Threedigitnumber;
Console.WriteLine("Enter in three whole numbers");
Threedigitnumber = int.Parse(Console.ReadLine());
sum = sum + (Threedigitnumber % 10); // Add third digit to sum
sum = sum + (Threedigitnumber / 10) % 10; // Add seconed digit to sum
sum = sum + (Threedigitnumber / 100); // Add first digit to sum
Console.WriteLine("{0} -> {1}", Threedigitnumber, sum);
Console.ReadKey();
}
}
}
Can someone please explain to me how and why this code works to calculate the sum of three numbers? Im confused on how exactly the % works and why division is needed here? How does this work?