Tsvetomir

Untitled

Nov 20th, 2012
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.18 KB | None | 0 0
  1. /*
  2.  * Author: Tsvetomir Nikolov
  3.  *
  4.  * Task 4: Write a program that reads two positive integer numbers and prints
  5.  * how many numbers p exist between them such that the reminder of the division
  6.  * by 5 is 0 (inclusive).
  7.  *
  8.  */
  9.  
  10. using System;
  11.  
  12. namespace DivisionBy5
  13. {
  14.     class DivisionBy5
  15.     {
  16.         static void Main()
  17.         {
  18.             int minValue;
  19.             do
  20.             {
  21.                 Console.Write("Insert min range value: ");
  22.             } while (!int.TryParse(Console.ReadLine(), out minValue));
  23.  
  24.             int maxValue;
  25.             do
  26.             {
  27.                 Console.Write("Insert max range value: ");
  28.             } while (!int.TryParse(Console.ReadLine(), out maxValue));
  29.  
  30.             if(minValue > maxValue)
  31.             {
  32.                 Console.WriteLine("Max value must be bigger than the min value.");
  33.                 return;
  34.             }
  35.  
  36.             int count = 0;
  37.  
  38.             if (minValue % 5 == 0 || maxValue % 5 == 0)
  39.                 count++;
  40.  
  41.             count += (maxValue - minValue) / 5;
  42.             Console.WriteLine("There are {0} numbers divisibles of 5 in range of [{1}:{2}].", count, minValue, maxValue);
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment