返回顶部

一缕半夏微光

温柔半两,从容一生

导航

编写程序,用 while 循环语句实现下列功能:有一篮鸡蛋,不止一个,有人两个两 个数,多余一个,三个三个数,多余一个,再四个四个地数,也多余一个,请问这篮鸡蛋至 少有多少个。(C#)

一、效果如下:

二、代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Test3
{
    class Program
    {
        static void Main(string[] args)
        {
            //设置鸡蛋个数的总量为2,因为一篮鸡蛋里不止一个
            int num = 2;
            bool check=false;
            while (num < int.MaxValue && check == false)
            {
                if(num % 2 == 1 && num % 3 == 1 && num % 4 == 1){
                    Console.WriteLine("这篮鸡蛋里一共有{0}个", num);
                    check = true;
                }else{
                    num++;
                } 
            }
            Console.ReadKey();
        }
    }
}

posted on 2021-10-13 17:42  一缕半夏微光  阅读(165)  评论(0编辑  收藏  举报