2020-09-25

4.百元买百鸡问题 

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

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, c;
            for (a = 0; a < 30; a++)
                for (b = 0; b < 75; b++)
                    for (c = 0; c < 150; c++)
                        if (a + b + c == 150 && (5 * a + 2 * b + c / 5 == 150) && c % 5 == 0)
                            Console.WriteLine("母鸡{0}只,公鸡{1}只,鸡仔{2}只", a, b, c);
            Console.ReadLine();

        }
    }
}

5.韩信点兵

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

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            int x;
            for (x = 1; x <= 105; x++)
            {
                if (x % 3 == 2 && x % 5 == 3 && x % 7 == 5)
                    Console.WriteLine("韩信共有{0}个兵", x);
            }
            Console.ReadLine();


        }
    }
}

6.鸡兔同笼

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

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b;
            for (a = 1; a <= 50; a++)
            {
                for (b = 1; b <= 25; b++)
                {
                    if (2 * a + 4 * b == 100 && a + b == 30)
                        Console.WriteLine("鸡有{0}只,兔有{1}只", a, b);
                }
            }
            Console.ReadLine();



        }
    }
}

 7.100以内所有偶数的和

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

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            int i, s = 0;
            for (i = 1; i <= 100; i++)
            {
                if (i % 2 != 0)
                    continue;
                s += i;
            }
            Console.WriteLine("100以内的所有偶数之和为{0}", s);
            Console.ReadLine();




        }
    }
}

 8.水仙花数

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

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, c, d = 100;

            for (; d < 1000; d++)
            {
                a = d % 10;
                b = d / 10 % 10;
                c = d / 100;
                if (a * a * a + b * b * b + c * c * c == d)
                    Console.WriteLine("{0}是水仙花数", d);
            }
            Console.ReadLine();
        }
    }
}

 9.求1+3+5+......+n>500的最小正整数n

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

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = 1, s = 0;
            while (n > 0)
            {
                s += n;
                n = n + 2;
                if (s >= 500)
                    break;
            }
            Console.WriteLine("最小正整数为{0}", n);
            Console.ReadLine();

        }
    }
}

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值