20日,又是好快的一天,感觉什么都没有学到,今天不知道怎么了 ,困的要命,有时候思路还老跑偏,复习了一遍,基础还不是很牢固,以后的路要靠自己走。
今天的重点:
1:乘法表的输出:
static void Main(string[] args)
        {
            int tem=0;
            for (int i = 1; i <= 9; i++)
            {
                for (int j = 1; j <= i; j++)
                {
                    tem = i * j;
                    Console.Write("{0}*{1}={2}\t",i,j,tem );
                }
                Console.WriteLine();
            }
         
        }
定义两个循环,然后实现累乘
2:程序中都有函数,数据,控制,简单变量可以用来存储数据。常量一旦被赋值,不能再改变。
3:求最大公约数和最小公倍数,以前都是很传统的思想,今天有了一种新的思路,可以倒过来算,数字开始向前减或向后加。
static void Main(string[] args)
        {
              //最大公约数和最小公倍数
                Console.Write("请输入第一个数:");
                int num1 = int.Parse(Console.ReadLine());
                Console.Write("请输入第一个数:");
                int num2 = int.Parse(Console.ReadLine());
               
 
                //最大公约数
                if (num1 > num2)
                {
                    for (int i = num2; i > 0; i--)
                    {
                        if ((num1 % i == 0) && (num2 % i == 0))
                        {
                            Console.WriteLine("最大公约数是:{0}", i);
                            break;
 
                        }
                    }
                }
                else
                {
                    for (int i = num1; i > 0; i--)
                    {
                        if ((num1 % i == 0) && (num2 % i == 0))
                        {
                            Console.WriteLine("最大公约数是:{0}", i);
                            break;
 
                        }
                    }
 
                }
 
 
 
                //最小公倍数
                if (num1 > num2)
                {
                    for (int i = num1; i <= num2 * num1; i++)//上限就是num1*num2的乘积
                    {
                        if ((i % num1 == 0) && (i % num2 == 0))
                        {
                            Console.WriteLine("最小公倍数是:{0}", i);
                            break;
                        }
                    }
 
                }
 
 
                if (num1 < num2)
                {
                    for (int i = num2; i <= num2 * num1; i++)
                    {
                        if ((i % num1 == 0) && (i % num2 == 0))
                        {
                            Console.WriteLine("最小公倍数是:{0}", i);
                            break;
                        }
                    }
 
                }
            }
4:在程序中实现石头剪子布游戏:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] arr = new string[3] { "石头","剪刀","布"};
 
            Random randm = new Random();
            int Machine= randm.Next(1,4);        
 
            Console.WriteLine("请选择:1、石头   2、剪刀   3、布");
            int Enter=int .Parse ( Console.ReadLine());
           // Console.WriteLine("您选择了:{0}",arr[Enter ]);
            Console.WriteLine("电脑出:{0}",arr[Machine - 1]);
           switch (Enter)
            {
                case 1:
                    Resual1(Machine, Enter);
                    break;
                case 2:
                    Resual2(Machine, Enter);
                    break;
                case 3:
                    Resual3(Machine, Enter);
                    break;
            }
          
        }
 
        private static void Resual3(int machine, int enter)
        {
            if (enter - machine == 0)
            {
                Console.WriteLine("平");
            }
            else if (enter - machine == 2)
            {
                Console.WriteLine("恭喜你赢了!");
            }
            else
            {
                Console.WriteLine("很遗憾你输了!");
            }
        }
 
        private static void Resual2(int machine, int enter)
        {
            if (enter - machine == 0)
            {
                Console.WriteLine("平");
            }
            else if (enter - machine == -1)
            {
                Console.WriteLine("恭喜你赢了!");
            }
            else
            {
                Console.WriteLine("很遗憾你输了!");
            }
        }
 
        private static void Resual1(int machine,int enter)
        {
            if (enter -machine ==0)
            {
                Console.WriteLine("平");
            }
            else if (enter - machine == -1)
            {
                Console.WriteLine("恭喜你赢了!");
            }
            else
            {
                Console.WriteLine("很遗憾你输了!");
            }
       }
 
 
 
 
    }
}
当然,方法不只一种,还有其他方法,比这个简单,但是,因为是自己写出来的,感觉小有成就感,就记下来了。
明天又将是新的一天,希望明天感冒好起来,以新的态度迎接新的到来吧!