VelizarAvramov

13. Game of Numbers

Nov 5th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.09 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _13._Game_of_Numbers
  4. {
  5.     class GameOfNumbers
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             //Write a program, which finds all possible combinations in the interval between two numbers. The program should also find
  10.             //the last combination, in which a number’s digits are equal to a given magical number.
  11.             int n = int.Parse(Console.ReadLine());
  12.             int m = int.Parse(Console.ReadLine());
  13.             int magicNum = int.Parse(Console.ReadLine());
  14.             int sumDigits = 0;
  15.             int count = 0;
  16.  
  17.             for (int i = m; i >= n; i--)
  18.             {
  19.                 for (int k = m; k >= n; k--)
  20.                 {
  21.                     count++;
  22.                     if (i + k == magicNum)
  23.                     {
  24.                         Console.WriteLine($"Number found! {i} + {k} = {magicNum}");
  25.                         return;
  26.                     }                  
  27.                 }
  28.             }
  29.             Console.WriteLine($"{count} combinations - neither equals {magicNum}");
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment