using System;
using System.Collections.Generic;
using System.Text;
namespace AVG
{
class Program
{
static void Main(string[] args)
{
double [] myArray = new double[10];
double sum = 0;
double avg = 0;
Console.WriteLine("请输入十个数");
for (int i = 0; i < 10; i++)
{
myArray[i] = Convert.ToDouble(Console.ReadLine());
sum += myArray[i];
}
avg = sum / 10;
Console.WriteLine("十个数的平均数为"+avg);
Console.ReadLine();
}
}
}
using System;
namespace HelloWorldApplication
{
class Program
{
static void Main(string[] args)
{
int[] change = { 23, 11, 44, 77, 7 };
int length = change.Length;//得到数组的长度
int i;
Console.WriteLine("原数组排序:");
for (i = 0; i < length; i++)//循环输出排序前的值
{
Console.WriteLine("{0}", change[i]);
}
//下面是Array.Sort升序排列
Array.Sort(change);
Console.WriteLine("数组升序后:");
for (i = 0; i < length; i++)
{
Console.WriteLine("{0}", change[i]);//循环输出Array.Srot升序排列结果
}
//下面是Array.Reverse降序排列后
Array.Reverse(change);
Console.WriteLine("数组降序后:");
for (i = 0; i < length; i++)
{
Console.WriteLine("{0}", change[i]);//循环输出Array.Reverse降序排列结果
}
Console.ReadKey();
}
}
}
using System;
namespace CalculatorApplication
{
class NumberManipulator
{
public int num;
public int factorial(int aVal)
{
int sum = 0;
if (aVal == 0)
{
return 0;
}
if (aVal == 1)
{
return sum = 1;
}
else if (aVal == 2)
{
return sum = 2;
}
else
{
int[] Fibo = new int[aVal];
for (int i = 0; i < aVal; i++)
{
Fibo[0] = 1;
Fibo[1] = 1;
for (int j = 3; j <= aVal; j++)
{
Fibo[j - 1] = Fibo[j - 2] + Fibo[j - 3];
}
sum = sum + Fibo[i];
}
}
return sum;
}
static void Main(string[] args)
{
NumberManipulator r = new NumberManipulator();
r.num = 100;
Console.WriteLine("斐波那契前100项的结果为:{0}", r.factorial(r.num));
Console.ReadLine();
}
}
}
using System;
namespace CalculatorApplication
{
class NumberManipulator
{
public int num1;
public int num2;
public int factorial(int num)
{
int result;
if (num == 1)
{
return 1;
}
else
{
result = factorial(num - 1) * num;
return result;
}
}
static void Main(string[] args)
{
NumberManipulator r = new NumberManipulator();
//调用 factorial 方法
r.num1 = 10;
r.num2 = 4;
int k;
k = r.num1 - r.num2;
Console.WriteLine("组合C(10,4)的结果为:{0}", r.factorial(r.num1)/ r.factorial(r.num2)/ r.factorial(k));
Console.ReadLine();
}
}
}