运算练习讲解

·小李有20个苹果,小王有10根香蕉,他们想和对方进行交换,请实现:

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

namespace Chess
{
    class Program
    {
        static void Main(string[] args)
        {
            string xiaoLi = "20个苹果";
            string xiaoWang = "10根香蕉";
            string t = xiaoLi;
            xiaoLi = xiaoWang;
            xiaoWang= t;
            Console.WriteLine("小李有:"+xiaoLi);
            Console.WriteLine("小王有:" + xiaoWang);
        }
    }
}

·计算任意三门成绩的总分,平均分(Csharp Unity Math)

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

namespace Chess
{
    class Program
    {
        static void Main(string[] args)
        {
            float Csharp = 99, Unity = 100, Math = 60;
            float sum = Csharp + Unity + Math;
            float avg = sum / 3;
            Console.WriteLine("总分为:" + sum);
            Console.WriteLine("平均分为:" + avg);
        }
    }
}

·计算一个半径为5的圆的面积和周长

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

namespace Chess
{
    class Program
    {
        static void Main(string[] args)
        {
            const float PI = 3.14159f;
            int r = 5;
            float C = 2 * PI * r;
            float S = PI * r * r;
            Console.WriteLine("周长为:" + C);
            Console.WriteLine("半径为:" + S);
        }
    }
}

·某商店T-shirt价格为285元/件,裤子的价格为720元/条,小李在该店买了2件T-shirt和3条裤子,请计算小李应该付多少钱?打3.8折之后呢?

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

namespace Chess
{
    class Program
    {
        static void Main(string[] args)
        {
            float cloth = 285;
            float trousers = 720;
            float total = 2 * cloth + 3 * trousers;
            float cheaper = total * 0.38f;
            Console.WriteLine("本次消费的总价为:" + total+"元");
            Console.WriteLine("打折后的价格为:" + cheaper + "元");
        }
    }
}

该系列专栏为网课课程笔记,仅用于学习参考。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值