Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Collections.Specialized;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace myloyorrr
- {
- internal class Program
- {
- static void PrintComponents(int n, int sum, int cur, string slag)
- {
- if (sum == n && cur != n)
- {
- Console.WriteLine(slag + " = " + n);
- }
- else
- {
- for(int i = cur; i < n - sum+1; i++)
- {
- if (sum + i < n)
- {
- PrintComponents(n, sum+i, i, slag+i+"+");
- }
- else
- {
- if(sum + i == n)
- {
- PrintComponents(n,sum+i,i, slag+i);
- }
- }
- }
- }
- }
- static void Main()
- {
- Console.Write("Введите необходимое число: ");
- int n = int.Parse(Console.ReadLine());
- Console.WriteLine($"Все возможные разложения числа {n} на слагаемые:");
- PrintComponents(n, 0, 1, "");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement