Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- /*11* Write a program that reads two positive integer numbers and prints how many numbers p exist between them such that the reminder of the division by 5 is 0. Examples:
- start end p comments
- 17 25 2 20, 25
- 5 30 6 5, 10, 15, 20, 25, 30
- */
- class DividableByGivenNumber
- {
- static void Main()
- {
- Console.Write("Enter start number: ");
- int startNum = int.Parse(Console.ReadLine());
- Console.Write("Enter end number: ");
- int endNum = int.Parse(Console.ReadLine());
- Console.Write("Enter P: ");
- int p = int.Parse(Console.ReadLine());
- if (startNum >= endNum)
- {
- Console.WriteLine("Invalid input");
- }
- for (int i = 0; i < p; i++)
- {
- while (startNum % 5 != 0)
- {
- startNum++;
- }
- if (startNum % 5 == 0 && startNum <= endNum)
- {
- Console.Write(startNum + ", ");
- startNum = startNum + 5;
- }
- }
- Console.WriteLine();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement