1、求min与max间数的所有奇数的和
static void Main(string[] args)
{ Console.WriteLine(res);
Console.ReadKey();
}
private static int Munodd(int min,int max)
{
int num = 0;
for (int i = min; i <= max; i++)
{
if (i % 2 == 1)
{
num += i;
}
}
return num;

 2、找数组中的最大数
int[] arr = { 12, 34, 56, 22, 87, 23, 67, 98, 543, 21, 2 };
int ars = GetMaxArray(arr);
Console.WriteLine(ars);
Console.ReadKey();
}
private static int GetMaxArray(int[] arr)
{
int max =arr[0];
for (int i = 0; i < arr.Length; i++)
{
if (max < arr[i])
{
max = arr[i];
}
}
return max;

3、0-100的素数

class Program
{
static void Main(string[] args)
{
int min = 0;
int max = 100;
int sount = 0;
for (int i = min; i <= max; i++)
{
if (Sushu(i) == true)
{
Console.WriteLine(i);
sount++;
}
}
Console.WriteLine("total:{0}",sount);
Console.ReadKey();
}

private static bool Sushu(int number)
{
if (number < 2)
{
return false;
}
for (int i = 2; i < number; i++)
{
if (number % i == 0)
{ return false; }
}
return true;
}
}

posted on 2012-07-13 00:09  Fan帥帥  阅读(176)  评论(0编辑  收藏  举报