, C# , . .
. . , .
static void Main(string[] args)
{
float[][] b; //
int n, m;
Console.Write(" ");
n = Convert.ToInt32(Console.ReadLine());
b = new float[n][]; //
for (int i = 0; i < n; i++)
{
Console.Write(" "+i+" ");
m = Convert.ToInt32(Console.ReadLine());
b[i] = new float[m]; //
// i-
}
for(int i=0;i<b.Length;i++)
for (int j = 0; j < b[i].Length; j++)
{
Console.Write("b[" + i + "," + j + "]=");
b[i][j] = Convert.ToSingle(Console.ReadLine());
}
float []dol=new float[n]; //
//
int kol;
float maxdol=0; //
for(int i=0;i<b.Length;i++)
{
kol=0;
for (int j = 0; j < b[i].Length; j++)
if(b[i][j]>0)kol++;
if (b[i].Length!=0)
dol[i]=(float)kol/b[i].Length;
else
dol[i]=0;
if(maxdol<dol[i])maxdol=dol[i];
}
if (maxdol == 0)
Console.WriteLine
(" ");
else
{
string s=""; //
for(int i=0;i<b.Length;i++)
if (dol[i]==maxdol) s+=" "+i;
Console.WriteLine
(" "+s);
}
Console.ReadLine();
}
.
- b , b.Length , b[i].Length i .
- , b[i].Length=0.
- string s=""; , .
1. , :
int i = 10, j = 9;
float x;
x = i / j; ? ?
2. ?
3. foreach?
4. Length ( ,
)?
5. GetUpperBound(i)
i?
C#, , :
- , .
- : , .
C# ( void). - , .
|
|
.
:
ref , .
ut .
, , .
.
1.
, .
void Nom1(out int k, int []mas)
{
int i;
k=-8;
for(i=0;i<mas.Length;i++)
if(mas[i]<0){k=i;break;}
}
k .
:
int Nom2(int []mas)
{
int i;
k=-8;
for(i=0;i<mas.Length;i++)
if(mas[i]<0){k=i;break;}
return k;
}
2.
. .
void Number(ref int k,double c1,double c2,double[]mas)
{
for(int i=k;i<mas.Length;i++)
if (mas[i] > c1 && mas[i] < c2) { k = i; break; }
}
k ( !) . 1 2 .
, , , .
2.2. C#
. , 1.1. , .
1.
namespace ConApp3
{
class Program
{
static void Nom1(out int k, int[] mas)
{
int i;
k = -8;
for (i = 0; i < mas.Length; i++)
if (mas[i] < 0) { k = i; break; }
}
static void Main(string[] args)
{
int[] m ={5,9,2,6,7,56,-100};
int p;
Nom1(out p, m);
if (p < 0) Console.WriteLine(" ");
else
Console.WriteLine(" "+p);
Console.ReadLine();
}
} }
Main Program , . static. , out.
2.
namespace ConApp3
{
class Program
{
void Number(ref int k, double c1, double c2,
double[] mas)
{
for (int i = k; i < mas.Length; i++)
if (mas[i] > c1 && mas[i] < c2)
{ k = i; break; }
}
static void Main(string[] args)
{
double[] m ={5.1,9.4,2.7,6.8,7.1,56.8,100.0};
int q=2;
Program myclass = new Program(); //1
myclass. Number(ref q, 8.0, 15.0, m); //2
Console.WriteLine(" "+q);
Console.ReadLine();
|
|
} } }
static , ( // 1). Program ( // 2). , ref.
, :
- ,
- .
, , .
namespace ConApp4
{
class Program
{
static int t1 = 0;
//
static void Inpt(int[][] k)
{ //
int n, m;
t1++; //
for (int i = 0; i < k.Length; i++)
for (int j = 0; j < k[i].Length; j++)
{
Console.Write("massiv[" + i + "," + j + "]=");
k[i][j] = Convert.ToInt32(Console.ReadLine());
}
}
static float Proc(int[][] d)
{ //
float sr = 0;
int kol = 0;
t1+=5; //
for(int i=0;i<d.Length;i++)
for (int j = 0; j < d[i].Length; j++)
{
sr += d[i][j];
kol++;
}
return sr / kol;
}
static void Main(string[] args)
{
int[][] mas;
int n, m;
Console.Write(" ");
n = Convert.ToInt32(Console.ReadLine());
mas = new int[n][]; //
for (int i = 0; i < n; i++)
{
Console.Write(" " + i + " ");
m = Convert.ToInt32(Console.ReadLine());
mas[i] = new int[m]; //
// i-
}
Inpt(mas);
Console.WriteLine(" " +
Proc(mas)+
+ t1=+t1); //
Console.ReadLine();
} } }
C# , .
namespace ConApp6
{
class Program
{
static int[] fun1(int[] k)
{ // -
int kol = 0;
for (int i = 0; i < k.Length; i++)
if (k[i] > 0) kol++;
int []res=new int[kol]; // -
kol = 0;
for (int i = 0; i < k.Length; i++)
if (k[i] > 0) res[kol++] = k[i];
return res; //
}
static void Main(string[] args)
{
int[] mas,arr; // mas arr -
int n;
Console.Write("Count of Elements ");
n = Convert.ToInt32(Console.ReadLine());
mas = new int[n];
for (int i = 0; i < mas.Length; i++)
{
Console.Write("mas[" + i + "]=");
mas[i] = Convert.ToInt32(Console.ReadLine());
}
arr = fun1(mas); // -
//
for (int i = 0; i < arr.Length; i++)
Console.WriteLine("arr[" + i + "]="+arr[i]);
Console.ReadLine();
}
}
}
1. ?
2. out ref?
3. static?
4. ?
3. - C#
- . - . . . , . C# , .
- :
|
|
- ( );
- ( , , );
- ( ).
C#.