Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Output to get sum = 5 in given array of integers
//Title of this code //Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { int[] num = new int[] {1, 3 ,2 ,2 ,5, 1}; int[] number = new int[num.Length]; for (int a = 0; a < num.Count(); a++) { number[a] = num[a]; } int sum; bool found = false; for (int i = 0; i < num.Count(); i++) { sum = 0; for (int j = i; j < num.Count(); j++) { sum = sum + number[j]; if (sum == 5) { found = true; for (int k = i; k < j; k++) { Console.Write("{0} + ", number[k]); } Console.Write(number[j]); Console.Write(" = 5\n"); } } } if (found == false) { Console.WriteLine("no zero subset\n\n"); } } } }
run
|
edit
|
history
|
help
0
sdfghjkilujyht
123
Problem: on_off
Math Main
calc
TestKlasse
Huffman Algorithm
sample code
RomaSlot2
tax cal