using System;
using System.Collections.Generic;
using System.Text;namespace famaWeight
{
public class Program
{
//建立验证天平左右的砝码是否相等的函数Check
static bool Check(int a, int b, int c, int d)
{
int i, j, k, l;
i = j = k = l = 0;
for (int r = 1; r <= 40; r++)
{
for (i = -1; i <= 1; i++)
for (j = -1; j <= 1; j++)
for (k = -1; k <= 1; k++)
for (l = -1; l <= 1; l++)
{
if (a * i + b * j + c * k + d * l == r)
goto NextLoop;
}
return false;
NextLoop;
continue;
}
return true;
}
//称重函数
static void Main(string[] args)
{
int a, b, c, d;
for (a = 1; a < 40; a++)
for (b = 1; b < 40; b++)
for (c = 1; c < 40; c++)
for (d = 1; d < 40; d++)
{
if (a + b + c + d == 40)
{
if (Check(a, b, c, d))
{
Console.WriteLine("{0}\t{1}\t{2}\t{3}", a, b, c, d);
}
}
}
Console.WriteLine("DONE");
Console.ReadLine();
}
}
}错误列表
错误 1 只有 assignment、call、increment、decrement 和 new 对象表达式可用作语句 D:\c#\我的C#程序\projects\famaWeight\famaWeight\Program.cs 25 17 famaWeight
错误 2 当前上下文中不存在名称“NextLoop” D:\c#\我的C#程序\projects\famaWeight\famaWeight\Program.cs 25 17 famaWeight
using System.Collections.Generic;
using System.Text;namespace famaWeight
{
public class Program
{
//建立验证天平左右的砝码是否相等的函数Check
static bool Check(int a, int b, int c, int d)
{
int i, j, k, l;
i = j = k = l = 0;
for (int r = 1; r <= 40; r++)
{
for (i = -1; i <= 1; i++)
for (j = -1; j <= 1; j++)
for (k = -1; k <= 1; k++)
for (l = -1; l <= 1; l++)
{
if (a * i + b * j + c * k + d * l == r)
goto NextLoop;
}
return false;
NextLoop;
continue;
}
return true;
}
//称重函数
static void Main(string[] args)
{
int a, b, c, d;
for (a = 1; a < 40; a++)
for (b = 1; b < 40; b++)
for (c = 1; c < 40; c++)
for (d = 1; d < 40; d++)
{
if (a + b + c + d == 40)
{
if (Check(a, b, c, d))
{
Console.WriteLine("{0}\t{1}\t{2}\t{3}", a, b, c, d);
}
}
}
Console.WriteLine("DONE");
Console.ReadLine();
}
}
}错误列表
错误 1 只有 assignment、call、increment、decrement 和 new 对象表达式可用作语句 D:\c#\我的C#程序\projects\famaWeight\famaWeight\Program.cs 25 17 famaWeight
错误 2 当前上下文中不存在名称“NextLoop” D:\c#\我的C#程序\projects\famaWeight\famaWeight\Program.cs 25 17 famaWeight
后边应当是冒号“:”,不是分号