Seal_of_approval

Pr5R2ex14

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