settingsAccountsettings
Menusettings

Q: Check for integer if it can be divided by 7 and 5 in the same time

+3 votes

I need to write a boolean expression that checks for given integer if it can be divided by 7 and 5 in the same time (without remainder) in C#.

Examples:

n

Divided by 7 and 5?

3

false

0

false

5

false

7

false

35

true

140

true

 

asked in C# category by user Jolie Ann

2 Answers

+2 votes
 
Best answer

the answer:

using System;

class DivideBySevenAndFive
{
    static void Main()
    {
        Console.WriteLine("Please enter your number:");
        double n = double.Parse(Console.ReadLine());

        bool result = (n % 5 == 0) && (n % 7 == 0);
        Console.WriteLine("The number {0} can be divided by 5 and 7? ANSWER: {1}",n, result);
    }
}
answered by user andrew
edited by user golearnweb
+1 vote

My answer:

using System;

class DivideBy7And5
{
    static void Main()
    {
        Console.WriteLine("Enter integer number:");
        int numInt = int.Parse(Console.ReadLine());
        bool checkNum7 = (numInt % 7) == 0;
        bool checkNum5 = (numInt % 5) == 0;
        if (numInt == 0)
        {
            checkNum7 = false;
        }
        Console.WriteLine("Divided by 7 and 5? {0}", checkNum7 && checkNum5);
    }
}
answered by user paulcabalit
edited by user golearnweb
...