1、一数列的规则如下:1、1、2、3、5、8、13、21、34…………,求第30位数是多少?
代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int x = 1, y = 1;
for (int i = 0; i <=28; i++)
{
int z = x + y;
x = y;
y = z;
}
Console.WriteLine(z);
Console.ReadKey();
}
}
}
2、输入一年份,判断是否闰年(被4整除,且不被100整除,或者被400整除)?
代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string year=Console.ReadLine();
int y = int.Parse(year);
if ((y % 4 == 0 && y % 100 != 0) || y % 400 == 0)
{
Console.WriteLine(y+"是闰年");
}
else
{
Console.WriteLine(y+"不是闰年");
}
Console.ReadKey();
}
}
}
代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string[] a = Console.ReadLine().Split(' ');
int sum = 0;
int max = -10, min = 1000;
for (int i = 0; i < 10; i++)
{
int b=int.Parse(a[i]);
if (max < b)
max = b;
if (min > b)
min = b;
sum += b;
}
double aver;
aver = (sum - max - min) / 8.0;
Console.WriteLine(aver);
Console.ReadKey();
}
}
}
代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string s = Console.ReadLine();
char[] c = s.ToCharArray();
bool f=true;
for (int i = 0, j = c.Length-1; i < c.Length; i++, j--)
{
if (i == j || j < i)
break;
if (c[i] != c[j])
{
f = false;
break;
}
}
if (f)
Console.WriteLine(s + "是回文字符串");
else
Console.WriteLine(s + "不是回文字符串");
Console.ReadKey();
}
}
}