Seal_of_approval

Pr4R7ex7

Sep 11th, 2015
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.65 KB | None | 0 0
  1. using System;
  2.  
  3. namespace test
  4. {
  5.     class Program
  6.     {
  7.         static bool isAnswer (int a, int k)
  8.         {
  9.             int j;
  10.             int count = 0;
  11.             for (int i = a; i > 0; i/=10) {
  12.                 j = i % 10;
  13.                 if (j % 2 == 0)
  14.                     count += 1;
  15.             }
  16.             if (count == k)
  17.                 return true;
  18.             else
  19.                 return false;
  20.         }
  21.         static void Main ()
  22.         {
  23.             Console.WriteLine ("Enter a & b ");
  24.  
  25.             int a = int.Parse (Console.ReadLine ());
  26.             int b = int.Parse (Console.ReadLine ());
  27.  
  28.             Console.WriteLine ("Enter K ");
  29.             int k = int.Parse (Console.ReadLine ());
  30.             for (int i = a; i <= b; i++) {
  31.                 if (isAnswer (i, k) == true)
  32.                     Console.WriteLine ("{0} ", i);
  33.             }
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment