kirililchev3

Test Numbers - for loops

May 20th, 2018
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.10 KB | None | 0 0
  1. using System;
  2.  
  3. namespace P12TestNumbers
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int n = int.Parse(Console.ReadLine());
  10.             int m = int.Parse(Console.ReadLine());
  11.             int boundary = int.Parse(Console.ReadLine());
  12.  
  13.             int countOfComb = 0;
  14.             double result = 0.0;
  15.  
  16.             for (int i = n; i >= 1; i--)
  17.             {
  18.                 for (int j = 1; j <= m; j++)
  19.                 {
  20.                     if (result >= boundary)
  21.                     {
  22.                         break;
  23.                     }
  24.                     result += (i * j) * 3;
  25.                     countOfComb++;
  26.                 }
  27.             }
  28.             if (result >= boundary)
  29.             {
  30.                 Console.WriteLine($"{countOfComb} combinations");
  31.                 Console.WriteLine($"Sum: {result} >= {boundary}");
  32.             }
  33.             else
  34.             {
  35.                 Console.WriteLine($"{countOfComb} combinations");
  36.                 Console.WriteLine($"Sum: {result}");
  37.             }
  38.            
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment