学习软件设计——C#练习(1)

C#练习(1~8)源代码下载请到http://download.csdn.net/detail/hsttmht/3751088

引用请注明http://blog.csdn.net/hsttmht

 

1.编写一个类,要求从控制台输入长方形的长和宽,计算面积和周长并且输出到控制台。


2.编写一个类,要求从控制台输入年份,计算输入的年份是否为闰年,闰年的判断是能被4整除并且不能被100整除,或者是能被400整除的年份
bool 是否为闰年 = (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);


3、编写一个类,要求从控制台输入3个数字,计算输入的3个数中最大的数,并且输出。


using System;
using System.Collections.Generic;
public class MyClass
{
	public static void Main()
	{
	    Console.WriteLine("请输入长方形的长:");
		int a=int.Parse(Console.ReadLine());
		Console.WriteLine("请输入长方形的宽:");
		int b=int.Parse(Console.ReadLine());
		Console.WriteLine("长方形的面积为:{0}",a*b);
		Console.WriteLine("长方形的周长为:{0}",(a+b)*2);
		Console.ReadLine();		
	}
}

using System;
using System.Collections.Generic;
public class MyClass
{
	public static void Main()
	{
	    Console.WriteLine("请输入日期:");
		int year=int.Parse(Console.ReadLine());
		if((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))


		{
			Console.WriteLine("为闰年");
		}
		else
		{
			Console.WriteLine("不为闰年");
		}
		Console.ReadLine();		
	}
	
}


using System;
using System.Collections.Generic;

public class MyClass
{
	public static void Main()
	{
		Console.WriteLine("请输入第1个数字:");
		int a = int.Parse(Console.ReadLine());
		Console.WriteLine("请输入第2个数字:");
		int b = int.Parse(Console.ReadLine());
		Console.WriteLine("请输入第3个数字:");
		int c = int.Parse(Console.ReadLine());
		int temp = 0;
		if(a > b)
		{
			temp = a;
			a = b ;
			b = temp;
		}
		if(a > c)
		{
			temp = a;
			a = c;
			c = temp;	 
		}
		if (b > c)
		{
			temp = b;
			b =  c;
			c = temp;
		}

		Console.WriteLine("最大的数: {0}",c);
		Console.ReadLine();
		
	}
}




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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值