Synchronization of old projects
Part1
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
using System;
|
||||
namespace Lesson7
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static int Compare(int a, int b)
|
||||
{
|
||||
int max = (a > b) ? a : b;
|
||||
return max;
|
||||
}
|
||||
|
||||
static float[] Circle(float r)
|
||||
{
|
||||
float pi = 3.14f;
|
||||
float perimeter = 2 * pi * r;
|
||||
float area = pi * (r * r);
|
||||
return new float[] { perimeter, area };
|
||||
}
|
||||
static int[] ComplexCompare(int[] a)
|
||||
{
|
||||
int sum = 0, min = a[0],max = a[0],avg=0;
|
||||
for (int i = 0; i < a.Length; i++)
|
||||
{
|
||||
sum += a[i];
|
||||
if (a[i] > max)
|
||||
{
|
||||
max = a[i];
|
||||
}
|
||||
if (a[i] < min)
|
||||
{
|
||||
min = a[i];
|
||||
}
|
||||
}
|
||||
avg = sum / a.Length;
|
||||
return new int[] { sum, max, min, avg };
|
||||
}
|
||||
static bool Primenumber(int a)
|
||||
{
|
||||
for (int i = 2; i < a; i++)
|
||||
{
|
||||
if (a % i == 0)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
static bool Year(int a)
|
||||
{
|
||||
if (a%400 == 0 || (a%4 == 0 && a%100 != 0))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
static void Main(string[] arg)
|
||||
{
|
||||
Console.WriteLine("比较大小:");
|
||||
Console.WriteLine(Compare(10, 20));
|
||||
|
||||
Console.WriteLine("圆:");
|
||||
float[] circle = Circle(20);
|
||||
Console.WriteLine("perimeter:" + circle[0] + " " + "area:" + circle[1]);
|
||||
|
||||
Console.WriteLine("综合:");
|
||||
int[] x = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
|
||||
int[] result = ComplexCompare(x);
|
||||
Console.WriteLine("总和:" + result[0] + "最大" + result[1] + "最小" + result[2] + "平均" + result[3]);
|
||||
|
||||
bool result2 = Primenumber(21);
|
||||
if (result2)
|
||||
{
|
||||
Console.WriteLine("是质数");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("不是质数");
|
||||
}
|
||||
|
||||
Console.WriteLine("闰年:");
|
||||
Console.WriteLine(Year(2200));
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user