VelizarAvramov

12. Test Numbers

Nov 5th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.54 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _12._Test_Numbers
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             //Write a program, which finds all the possible combinations between two numbers – N and M.
  10.             //The first digit decreases from N to 1, and the second digit increases from 1 to M. The two digits form a number. Multiply
  11.             //the two digits, then multiply their product by 3. Add the result to the total sum.
  12.             //You will also be given a third number, which will be the maximum boundary of the sum. If the sum is equal or greater than
  13.             //this number you should stop the program. See the examples for further information.
  14.  
  15.             int n = int.Parse(Console.ReadLine());
  16.             int m = int.Parse(Console.ReadLine());
  17.             int maxSum = int.Parse(Console.ReadLine());
  18.  
  19.             int count = 0;
  20.             int sum = 0;
  21.  
  22.             for (int i = n; i >= 1; i--)
  23.             {
  24.                 for (int k = 1; k <= m; k++)
  25.                 {
  26.                     sum += i * k * 3;
  27.                     count++;
  28.                     if (sum >= maxSum)
  29.                     {
  30.                         Console.WriteLine($"{count} combinations");
  31.                         Console.WriteLine($"Sum: {sum} >= {maxSum}");
  32.                         return;
  33.                     }                    
  34.                 }
  35.             }
  36.             Console.WriteLine($"{count} combinations");
  37.             Console.WriteLine($"Sum: {sum}");
  38.             return;
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment