C#编程练习

答案:ACD

 答案:B

答案:ACD

 

编写代码如下:

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

namespace _1
{
    class Program
    {
        static void Main(string[] args)
        {
            //从键盘中输入3位正整数 按照数字相反的顺序输出
            Console.WriteLine("请输入一个3位的正整数\n");

          int m= Convert .ToInt32( Console.ReadLine());

            int a = m / 100;
            int b = (m % 100) /10;
            int c = m - a * 100 - b * 10;

            int n = c * 100 + b * 10 + a;
            Console.WriteLine("之前的值为{0},相反之后的值为{1}", m, n);

        }
    }
}

代码运行结果如下: 

 编写代码如下:

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

namespace _1
{
    class Program
    {
        static void Main(string[] args)
        {
            //千位和十位
            Console.WriteLine("请输入一个五位数:");
            int m = Convert.ToInt32(Console.ReadLine());
            int q =( m %10000) /1000;
            int s = (((m % 10000) % 1000) % 100) / 10;
            //qs
            int db = q * 10 + s;
            char dbz =(char) db;
            Console.WriteLine("这个电报的意思是{0}", dbz);
        }
    }
}

代码运行结果如下:

编写代码如下:

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

namespace _1
{
    class Program
    {
        static void Main(string[] args)
        {
            //输入数学和英语的分数,判断该分数是否有奖励。条件:分数两门都>=90
            Console.WriteLine("请输入数学的分数:");
            float s = Convert.ToInt32(Console.ReadLine ());
            Console.WriteLine("请输入英语的分数:");
            float y = Convert.ToInt32(Console.ReadLine ());
            if (s >= 90 && y >= 90)
                Console.WriteLine("有奖励");
            else
                Console.WriteLine("没有奖励");
        }
    }
}
 

运行结果如下:

 

 分析:a++是先使用再赋值。

b=a++ + a++

第一步:b=3;a=a++=4;

第二步:这个时候变成了在已知第一步的基础上,b=b + a++=3 + a++(因为b先使用再赋值,所以前面变成了b)

第三步:由于a++先使用,所以第二步中的b=3 + a++ =3+4 =7;算完之后a还要自增,所以a=5

最终a=5,b=7

分析:++a是先自增,再赋值。 同上分析可知,

第一步:a=3,b=a++ +4  此时a=4

第二步:b=4+4=8;然后a自增,值为5

最终a=5,b=8

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值