前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >C# 百钱买百鸡

C# 百钱买百鸡

作者头像
landv
发布2019-03-20 10:10:22
8900
发布2019-03-20 10:10:22
举报
文章被收录于专栏:landvlandv
代码语言:javascript
复制
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApp100鸡
{
    class Program
    {
        static void Main(string[] args)
        {


            Console.WriteLine("用百元钱买百只鸡,公鸡每只5元,母鸡每只3元,小鸡1元3只~那么它们各是几只?");
            int max = 100;
            for (int a = 0; a <= max / 5; a++)
                for (int b = 0; b <= max / 3; b++)
                    for (int c = 0; c <= max * 3; c++)
                        if ((a + b + c == 100) && (a * 5 + b * 3 + c / 3.0 == 100.0))
                            Console.WriteLine("公鸡:{0}\t母鸡:{1}\t小鸡:{2}", a.ToString().PadLeft(2, '0'), b.ToString().PadLeft(2, '0'), c.ToString().PadLeft(2, '0'));
            Console.WriteLine("完成");
            Console.ReadKey();
        }
    }
}
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-03-18 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档