Advertisement
emzone

Homework 4.11 - NumsInIntervalDividableByGivenNum

Mar 24th, 2014
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.57 KB | None | 0 0
  1. /*Problem 11. Numbers in Interval Dividable by Given Number
  2. Write a program that reads two positive integer numbers and prints how many numbers p exist between them such that
  3. the reminder of the division by 5 is 0.*/
  4.  
  5. using System;
  6.  
  7.     class NumsInIntervalDividableByGivenNum
  8.     {
  9.         static void Main()
  10.         {
  11.             Console.Write("Num1: ");
  12.             string num1Prompt = Console.ReadLine();
  13.             int num1 = int.Parse(num1Prompt);
  14.             Console.Write("Num2: ");
  15.             string num2Prompt = Console.ReadLine();
  16.             int num2 = int.Parse(num2Prompt);
  17.  
  18.             int p = 0;
  19.             if (num1 > num2)
  20.             {
  21.                 for (int i = num2; i <= num1; i++)
  22.                 {
  23.                     int result = i % 5;
  24.                     if (result == 0)
  25.                     {
  26.                         p += 1;
  27.                     }
  28.                 }
  29.                 Console.Write("p = " + p + "\n");
  30.             }
  31.            
  32.  
  33.             if (num1 < num2)
  34.             {
  35.                 for (int i = num1; i <= num2; i++)
  36.                 {
  37.                     int result = i % 5;
  38.                     if (result == 0)
  39.                     {
  40.                         p += 1;
  41.                     }
  42.                 }
  43.                 Console.Write("p = " + p + "\n");
  44.             }
  45.             if (num1 == num2)
  46.             {
  47.                 Console.WriteLine("There is no dividible difference between the numbers {0} and {1}.", num1, num2);
  48.                 Console.Write("p = " + p + "\n");
  49.             }
  50.         }
  51.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement