问题1: public int factorial(int number) { int Value =0; for (int i = 1; i <= number; i++) { Value += jiecheng(i); } return Value; } public int jiecheng(int n) { if (n == 1) return 1; else return n * jiecheng(n - 1); }
题目2: int total=0; int avag=0; int Number_1=0; int Number_2=0; foreach (int item in ary) { total += item; if (item > 0) { Number_1 += 1; } if (item < 0) { Number_2 += 1; } } avag = total / ary.Length;
这个区好象是C井区.
public int factorial(int number)
{
int Value =0;
for (int i = 1; i <= number; i++)
{
Value += jiecheng(i);
}
return Value;
} public int jiecheng(int n)
{
if (n == 1) return 1;
else return n * jiecheng(n - 1);
}
int avag=0;
int Number_1=0;
int Number_2=0; foreach (int item in ary)
{
total += item;
if (item > 0)
{
Number_1 += 1; } if (item < 0)
{
Number_2 += 1;
} }
avag = total / ary.Length;