
Larry C. answered 04/06/19
Computer Science and Mathematics professional
Not certain why the code isn't working as expected (I'm nowhere near as proficient in C# as other languages), but there's a tweak you might try which is also a tad more efficient. Since you only want to exclude those numbers divisible by both 3 and 7, change your modulo test to (a % 21 != 0). That saves you a modulo operation and compounded logical comparison every iteration of the loop.