svetlozar_kirkov

Two Numbers Count Divisible by 5 (Exercise)

Sep 28th, 2014
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.76 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace ConsoleTesting
  5. {
  6.     class ConsoleTesting
  7.     {
  8.         static void Main()
  9.         {
  10.             int first = int.Parse(Console.ReadLine());
  11.             int second = int.Parse(Console.ReadLine());
  12.             int count = 0;
  13.             List<int> collected = new List<int>();
  14.             for (int i = first; i <= second; i++)
  15.             {
  16.                 if (i % 5 == 0)
  17.                 {
  18.                     count++;
  19.                     collected.Add(i);
  20.                 }
  21.             }
  22.             Console.WriteLine(count);
  23.             foreach (var item in collected)
  24.             {
  25.                 Console.Write(item+" ");
  26.             }
  27.             Console.WriteLine();
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment