Advertisement
Dianov

Nested Loops - Lab (03. Combinations)

Dec 30th, 2020
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.75 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 Combinations
  8.  
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             int n = int.Parse(Console.ReadLine());
  15.             int counter = 0;
  16.             for (int a = 0; a <= n; a++)
  17.             {
  18.                 for (int b = 0; b <= n; b++)
  19.                 {
  20.                     for (int c = 0; c <= n; c++)
  21.                     {
  22.                         if (a + b + c == n)
  23.                         {
  24.                             counter += 1;
  25.                         }
  26.                     }
  27.                 }
  28.             }
  29.             Console.WriteLine(counter);
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement