settingsAccountsettings
Menusettings

Q: Program that prints a number which is divided by 9, 11 or 13 without remainder

+6 votes

Hi, I must write a program in C# that prints if a number (n) is divided by 9, 11 or 13 without remainder. Not by all of them but with one of them - either with 9 or with 11 or with 13 - I suppose I will need to use the logical operator || (or)...

Here's the output:

n

Result

121

true

1263

false

26

true

23

false

81

true

      1287

true

 

asked in C# category by user samfred5830

1 Answer

+1 vote
 
Best answer
  1. Declare two variables (n and result).
  2. Read the user input from the console. (int.Parse(Console.ReadLine());).
  3. Check if the input number is divided by 9, 11 or 13 using the logical operators:
    1. Use: (n % 9 == 0) || (n % 11 == 0) || (n % 13 == 0);
    2. || checks if the left expression OR the right expression have a true value. If only one has a true value the result is true;
    3. Save the result of the verification in the result variable;
  4. Print the result on the console (Console.WriteLine(result));)

using System;

class PureDivisor
{
    static void Main()
    {
        Console.WriteLine("Please write your number so the program can check \nwhether it can be devided by 9, 11 and 13.");
        int n = int.Parse(Console.ReadLine());

        bool result = (n % 9 == 0) || (n % 11 == 0) || (n % 13 == 0);
        Console.WriteLine("The answer is: {0}", result);
    }
}
answered by user john7
selected by user golearnweb
...