I was thinking % was the way to go as well. Maybe something like this?
Code:int x = 2; int y = 3; for (int i = 1; i <= 100; i++) { if ((i % x == 0) && (i % y == 0)) { Debug.WriteLine(i.ToString() + " is divisible by " + x.ToString() + " and " + y.ToString()); } else if (i % x == 0) { Debug.WriteLine(i.ToString() + " is divisble by " + x.ToString()); } else if (i % y == 0) { Debug.WriteLine(i.ToString() + " is divisible by " + y.ToString()); } }




Reply With Quote