假设 1 3 10 20 30 这些数字为数组int[] A 新建数组int[] B 新建数组string[] C 1.把小于25的数字放入 数组B`` 2.然后遍历B``然后写个单独的递归方法``方法是: B中的每个数字跟A中的每个数字相加``如果相加结果大于25且小于30``(这里还需要个临时变量string tempstring来保存相加的数字,在遍历循环中声明``)则将tempstring保存到数组C``且将结果继续递归(与A中数字相加)``否则跳出`` 3.输出数组string[] C
using System; using System.Collections.Generic; using System.Text;namespace ConsoleApplication1 { class Program { static void Main(string[] args) { for (int a = 0; a < 30; a++) { for (int b = 0; b < 10; b++) { for (int c = 0; c < 3; c++) { for (int d = 0; d < 2; d++) { int n = 1 * a + 3 * b + 10 * c + 20 * d; if (n > 25 && n < 30) { if (a != 0) for (int i = 0; i < a; i++) Console.Write("1,"); if (b != 0) for (int i = 0; i < b; i++) Console.Write("3,"); if (c != 0) for (int i = 0; i < c; i++) Console.Write("10,"); if (d != 0) for (int i = 0; i < d; i++) Console.Write("20,"); Console.Write("\n"); } } } } } Console.Read();
新建数组int[] B
新建数组string[] C
1.把小于25的数字放入 数组B``
2.然后遍历B``然后写个单独的递归方法``方法是: B中的每个数字跟A中的每个数字相加``如果相加结果大于25且小于30``(这里还需要个临时变量string tempstring来保存相加的数字,在遍历循环中声明``)则将tempstring保存到数组C``且将结果继续递归(与A中数字相加)``否则跳出``
3.输出数组string[] C
using System.Collections.Generic;
using System.Text;namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
for (int a = 0; a < 30; a++)
{
for (int b = 0; b < 10; b++)
{
for (int c = 0; c < 3; c++)
{
for (int d = 0; d < 2; d++)
{
int n = 1 * a + 3 * b + 10 * c + 20 * d;
if (n > 25 && n < 30)
{
if (a != 0)
for (int i = 0; i < a; i++)
Console.Write("1,");
if (b != 0)
for (int i = 0; i < b; i++)
Console.Write("3,");
if (c != 0)
for (int i = 0; i < c; i++)
Console.Write("10,");
if (d != 0)
for (int i = 0; i < d; i++)
Console.Write("20,");
Console.Write("\n");
}
}
}
}
}
Console.Read();
} }
}