Advertisement
Tsvetomir

Untitled

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