Advertisement
myname0

практикум 4 VII. 13

Sep 11th, 2015
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.39 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace практикум_4.VII._13
  8. {
  9.     class Program
  10.     {
  11.         static int NextLowerNumber(int c, int d, int n)
  12.         {
  13.             int k;
  14.             int number;
  15.             int tmp = -1;
  16.             bool flag = true;
  17.             for (int i = n-1; i > 0 && flag; i--)
  18.             {
  19.                 k = 0;
  20.                 number = i;
  21.                 while (number > 0)
  22.                 {
  23.                     k += number % 10;
  24.                     number /= 10;
  25.                 }
  26.                 if ((k % c == 0) || (k % d == 0))
  27.                 {
  28.                     flag = false;
  29.                     tmp = i;
  30.                 }
  31.                
  32.             }
  33.             return tmp;
  34.         }
  35.         static void Main(string[] args)
  36.         {
  37.             Console.WriteLine("Enter c:");
  38.             int c = int.Parse(Console.ReadLine());
  39.             Console.WriteLine("Enter d:");
  40.             int d = int.Parse(Console.ReadLine());
  41.             Console.WriteLine("Enter N:");
  42.             int n = int.Parse(Console.ReadLine());
  43.             int res = NextLowerNumber(c, d, n);
  44.             if (res == -1)
  45.                 Console.WriteLine("none minimal number is not divisible by c and d");
  46.             else Console.WriteLine("{0}", res);
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement