using System;
using System.Collections.Generic;
using System.Text;namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int x ,y ,z;
            x = y = z = 0;
            for (x = 1; x <= 100 / 5; x++)
                for (y = 1; y <= 100 / 3;y++ )
                {
                    z = 100 - x - y;
                    if (z % 3 == 0 && 5 * x + 3 * y + z == 100)
                        goto end;
                }
        end: Console.WriteLine("Cock={0} Hen={1} Chick = {2}", x, y, z);
            Console.Read();
        }
    }
}
哪里有问题,请高手指导下

解决方案 »

  1.   

    再加问下,C#的输入怎么描写?像C是scanf(“%d”,&x)
    最好举个小例子,多谢!!
      

  2.   

    再加问下,C#的输入怎么描写?像C是scanf(“%d”,&x)
    最好举个小例子,多谢!!
      

  3.   

    那 int Gread = (int)Consol.read(); 是什么意思嘞?
      

  4.   

    goto 在某些时候是相当有用的// statements_goto_switch.cs
    using System;
    class SwitchTest
    {
        static void Main()
        {
            Console.WriteLine("Coffee sizes: 1=Small 2=Medium 3=Large");
            Console.Write("Please enter your selection: ");
            string s = Console.ReadLine();
            int n = int.Parse(s);
            int cost = 0;
            switch (n)
            {
                case 1:
                    cost += 25;
                    break;
                case 2:
                    cost += 25;
                    goto case 1;
                case 3:
                    cost += 50;
                    goto case 1;
                default:
                    Console.WriteLine("Invalid selection.");
                    break;
            }
            if (cost != 0)
            {
                Console.WriteLine("Please insert {0} cents.", cost);
            }
            Console.WriteLine("Thank you for your business.");
        }
      

  5.   

    吗的我程序中经常用GOTO,方便死了,楼主这样一眼看上去象是没问题..GOTO真他吗太好了,我开始就一直用好几年了..不知到楼主在疑惑哙;
      

  6.   

    关于 goto,大家请看这段代码:  // 在 s 中查找 pattern 。
      // 如果找到,返回 pattern 在 s 中第一次出现的位置(0起始)。
      // 如果没找到,返回 -1。
      static int IndexOf(byte[] s, byte[] pattern) 
      { 
        int slen = s.Length;
        int plen = pattern.Length;
        for (int i = 0, j; i <= slen - plen; i++) 
        { 
          for (j = 0; j < plen; j++) 
          { 
            if (s[i + j] != pattern[j]) break;
          }
          if (j == plen) return i;
        }
        return -1;
      }
    用 goto 语句改写如下:  // 在 s 中查找 pattern 。
      // 如果找到,返回 pattern 在 s 中第一次出现的位置(0起始)。
      // 如果没找到,返回 -1。
      static int IndexOf(byte[] s, byte[] pattern) 
      { 
        int slen = s.Length;
        int plen = pattern.Length;
        for (int i = 0; i <= slen - plen; i++) 
        { 
          for (int j = 0; j < plen; j++) 
          { 
            if (s[i + j] != pattern[j]) goto next;
          }
          return i;
          next:;
        }
        return -1;
      }节省了在外层循环中判断 if (j == plen) ,可以提高效率,程序结构也更清晰。
      

  7.   

    程序运行的结果有问题…………好像不对哈……出来x,y,z是21,34,47,问题是100元买鸡,公鸡5元,母鸡3元,小鸡1元3只,问100可买公鸡、母鸡、小鸡各多少只!答案是4,18,78!
      

  8.   

     if (z % 3 == 0 && 5 * x + 3 * y + z == 100) 
    改为:
     if (z % 3 == 0 && 5 * x + 3 * y + z / 3 == 100)