Advertisement
Cosmin3105

Problema C#

Oct 30th, 2020
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.13 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ConsoleApplication1
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             int s, i, j, n, l = 0;
  13.             int[,] a;
  14.             n = int.Parse(Console.ReadLine());
  15.             a = new int[100,100];
  16.             for (i = 1; i <= n / 2; i++) {
  17.                 j = i;
  18.                 int[] v = new int[100];
  19.                 s = 0;
  20.                 while (s < n) {
  21.                     s += j;
  22.                     v[j-i+1] = j;
  23.                    
  24.                     j++;
  25.                 }
  26.  
  27.                 if (s == n) {
  28.                     for (int k = 1; k <= j - i + 1; k++)
  29.                         a[l, k] = v[k];
  30.                     l++;
  31.                 }
  32.             }
  33.  
  34.             for (i = 0; i < l; i++) {
  35.                 j = 1;
  36.                 while (a[i, j] != 0) {
  37.                     Console.Write(a[i, j] + " ");
  38.                     j++;
  39.                 }
  40.                 Console.WriteLine();
  41.             }
  42.            
  43.             Console.ReadLine();
  44.         }
  45.     }
  46. }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement