C#基础题求助!急!
一共有2题,急用,都是用C#控制台来写,谢谢大家了。1、10年之前,海边住着一个渔人,为了保护生态环境,此人决定3天打鱼2天晒网。于是问题来了:1998年1月1日开始打鱼,那么到今天(2009年3月13日)他是在打鱼,还是在晒网?编程解决这个问题。
2、 一球从100米高度自由落下,每次落地后反跳回原高度的一半;再落下,求它在 第10次落地时,共经过多少米?第10次反弹多高?
2012-11-14 09:56
程序代码:
using System;
namespace FishAndBallConsole
{
class Program
{
static void Main()
{
Console.Title = "Fish and Ball by ";
//fish
var fish = true;
var currentDateTime = DateTime.Parse("1998-1-1").Subtract(TimeSpan.FromDays(1));
var targetDateTime = DateTime.Parse("2009-3-13");
while (true)
{
if (fish)
currentDateTime += TimeSpan.FromDays(3);
else
currentDateTime += TimeSpan.FromDays(2);
if (currentDateTime >= targetDateTime) break;
fish = !fish;
}
Console.Write(targetDateTime.ToShortDateString());
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine(fish ? " DaYu" : " ShaiWang");
Console.ForegroundColor = ConsoleColor.Gray;
//ball
const int times = 10;
const double percentRebound = .5;
const double height = 100d;
var reboundPercent = percentRebound;
for (var i = 0; i < times - 1; i++)
reboundPercent *= percentRebound;
Console.Write("Rebound height ");
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine(height * reboundPercent);
Console.Read();
}
}
}

2012-11-14 12:26
2012-11-14 20:26
2012-11-14 20:30
2012-11-17 00:36
2012-11-17 01:02
2012-11-17 08:17
2012-11-18 19:09
2012-11-18 20:53