Number divisible by 6

This is a discussion on Number divisible by 6 within the C# Programming forums, part of the General Programming Boards category; I hate to be stupid but does this program solve the problem of testing an integer to be divisible by ...

  1. #1
    Registered User
    Join Date
    Jan 2010
    Posts
    150

    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!");
    
            }
        }
    }

  2. #2
    Registered User Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    650
    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.

  3. #3
    Registered User
    Join Date
    Jan 2010
    Posts
    150
    I got it now I should have tested it before I posted like you suggested

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ divisible by 10
    By [Student] in forum C++ Programming
    Replies: 5
    Last Post: 12-03-2011, 01:33 PM
  2. problem with program number divisible by 10? using macros
    By MarjunC in forum C++ Programming
    Replies: 5
    Last Post: 06-23-2010, 05:43 AM
  3. Divisible Program
    By Ericalvusa91 in forum C++ Programming
    Replies: 1
    Last Post: 04-27-2010, 05:25 PM
  4. Displaying Numbers divisible by user's desired number
    By DaniiChris in forum C Programming
    Replies: 9
    Last Post: 07-07-2008, 02:06 PM
  5. Divisible by 2
    By guillermoh in forum C Programming
    Replies: 22
    Last Post: 03-12-2008, 10:19 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21