Synchronization of old projects

Part1
This commit is contained in:
2025-09-30 16:46:01 +08:00
parent 116b65164b
commit 4e1548abe2
167 changed files with 8668 additions and 43 deletions
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
@@ -0,0 +1,60 @@
using System;
namespace Lesson
{
class Program
{
static void SumAndAvg(params int[] num)
{
if (num.Length == 0)
{
Console.WriteLine("没有东西");
return;
}
else
{
int sum = 0, avg;
for (int i = 0; i < num.Length; i++)
{
sum += num[i];
}
avg = sum / num.Length;
Console.WriteLine("总和为:" + sum);
Console.WriteLine("平均为:" + avg);
}
}
static void Calc(params int[] arr)
{
if(arr.Length == 0)
{
Console.WriteLine("没有东西");
return;
}
else
{
int sum1 = 0, sum2 = 0;
for (int i = 0; i < arr.Length; i++)
{
if (arr[i] % 2 == 0)
{
sum1 += arr[i];
}
else
{
sum2 += arr[i];
}
}
Console.WriteLine("奇数合:"+sum2);
Console.WriteLine("偶数合:"+sum1);
}
}
static void Main(string[] args)
{
SumAndAvg();
SumAndAvg(1,2,3,4,5,6,7,8,9,10);
Calc();
Calc(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
}
}
}