Advertisement
aluin

DividableByGivenNumber

Apr 1st, 2014
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. using System;
  2.  
  3. /*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:
  4. start end p comments
  5. 17 25 2 20, 25
  6. 5 30 6 5, 10, 15, 20, 25, 30
  7. */
  8.  
  9. class DividableByGivenNumber
  10. {
  11. static void Main()
  12. {
  13. Console.Write("Enter start number: ");
  14. int startNum = int.Parse(Console.ReadLine());
  15. Console.Write("Enter end number: ");
  16. int endNum = int.Parse(Console.ReadLine());
  17. Console.Write("Enter P: ");
  18. int p = int.Parse(Console.ReadLine());
  19.  
  20. if (startNum >= endNum)
  21. {
  22. Console.WriteLine("Invalid input");
  23. }
  24.  
  25. for (int i = 0; i < p; i++)
  26. {
  27. while (startNum % 5 != 0)
  28. {
  29. startNum++;
  30. }
  31.  
  32. if (startNum % 5 == 0 && startNum <= endNum)
  33. {
  34. Console.Write(startNum + ", ");
  35. startNum = startNum + 5;
  36. }
  37. }
  38. Console.WriteLine();
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement