Advertisement
Klaxon

[C# Operators] Can be Divided

Jul 8th, 2013
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.21 KB | None | 0 0
  1. // Write a boolean expression that checks for given integer if it can be divided (without remainder)
  2. // by 7 and 5 in the same time.
  3.  
  4. using System;
  5.  
  6. class CanBeDivided
  7. {
  8.     static void Main()
  9.     {
  10.         // Declaring needed variables
  11.         int number;
  12.         bool isValid;
  13.  
  14.         // Making validation
  15.         do
  16.         {
  17.             Console.WriteLine("Please enter a number between 2147483647 and -2147483647:");
  18.             isValid = int.TryParse(Console.ReadLine(), out number);
  19.         }
  20.         while (number < 2147483647 && number > -2147483647 && isValid == false);
  21.  
  22.         // If the number can be devided by 5 and 7 without remainder..
  23.         if (number % 5 == 0 && number % 7 == 0)
  24.         {
  25.             // ..print on the console
  26.             Console.WriteLine(isValid == true);
  27.             Console.WriteLine("The number can be devided by 5 and 7 at the same time.");
  28.         }
  29.  
  30.         // If the number can NOT be devided by 5 and 7 without remainder..
  31.         else
  32.         {
  33.             // ..print on the console
  34.             Console.WriteLine(isValid == false);
  35.             Console.WriteLine("The number CAN'T be devided by 5 and 7 at the same time!");
  36.            
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement