您的位置:首页 > 编程语言 > C#

[C#]数字颠倒输出;判断某天是一年中的第几天

2014-03-10 21:09 183 查看
数字颠倒输出:

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

namespace 数字颠倒输出
{
class Program
{
static void Main(string[] args)
{
int n;
String s = Console.ReadLine();
n = int.Parse(s);
while (n!=0)
{
Console.Write(n % 10);
n /= 10;
}
}
}
}


判断某天是一年中的第几天:

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

namespace 第几天
{
class Program
{
static void Main(string[] args)
{
int []num={0,31,29,31,30,31,30,31,31,30,31,30,31};
int year,month,day;
string temp=Console.ReadLine();
year=int.Parse(temp);
temp=Console.ReadLine();
month=int.Parse(temp);
temp=Console.ReadLine();
int sum=0;
day=int.Parse(temp);
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
{
for (int i = month - 1; i >= 1; i--)
sum += num[i];
if (month >= 3)
sum--;
sum += day;
Console.WriteLine(sum);

}
else
{
for (int i = month - 1; i >= 1; i--)
sum += num[i];
sum += day;
Console.WriteLine(sum);
}

}
}
}


 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: