-
Number divisible by 6
I hate to be stupid but does this program solve the problem of testing an integer to be divisible by 6?
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Chapter7Problem5
{
class Program
{
static void Main()
{
int number;
Console.Write("\nEnter a integer: ");
number = Convert.ToInt32(Console.ReadLine());
if ((number % 2 == 0) && (number % 3 == 0))
Console.Write("\nThe number is divisible by 6!");
else
Console.Write("\nThe number is not divisible by 6!");
}
}
}
-
If you wanted to test if a number is divisible by 6 why wouldn't you simply test for number % 6? But yes, a number that's divisible by 6 has the common factors of 2 and 3.
-
I got it now I should have tested it before I posted like you suggested