C#实现猜数游戏

来源:互联网 发布:cdr软件图标 编辑:程序博客网 时间:2024/06/02 01:56
原文地址:sharp 实现 猜数游戏  (产生0-100随机数,试试才几次能猜对)作者:陈振亚czy
namespace lianxi6._29_1{    class Program    {       static void Main(string[] args)       {           Random r =new Random();           int b =r.Next(0, 100);           int count= 1;          Console.ReadLine("请输入您猜的数字:");           cc:           int a =int.Parse(Console.ReadLine());           f(a,b);           if (a ==b) { Console.Write("您猜对了,用了{0}次",count); }          count++;           gotocc;          Console.ReadLine();       }       static void f(int a,int b)       {                  if (a >b)           {             Console.Write("您猜的数大了n");           }           else if (a< b)           {              Console.Write("您猜的数小了n");                    }                 }    }}



原创粉丝点击