Работа со структурой - C#
Формулировка задачи:
Добрый день!
Подскажите, пожалуйста, как обратиться к конкретному элементу массива в С#. И помимо этого, в программе выдает ошибки там где вызываются функции. Помогите, пожалуйста
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
public const int m = 20, n = 15;
public double[,] A = new double [m,n];
public struct str{
double num1=1;
double num2=1;
double bol=0;
double men=0;}
int Arr()
{
for (int i = 1; i < m; i++)
{
for (int j = 1; j < n; j++)
{
A[i, j] = (i + j) / Math.Log(1 + j);
}
}
return 0;
}
void Viv()
{
for (int i = 1; i < m; i++)
{
for (int j = 1; j < n; j++)
{
System.Console.Write(A[i, j]);
}
System.Console.WriteLine();
}
}
int Vic()
{
double summ;
for (int i = 1; i < m; i++)
{
summ = 0;
for (int j = 1; j < n; j++)
{
summ = summ + A[i, j];
}
if (i == 1)
{
str->men = summ;
}
else
{
if (summ > bol)
{
bol = summ;
num1 = i;
}
if (summ < men)
{
men = summ;
num2 = i;
}
}
}
return 0;
}
int Res()
{
System.Console.WriteLine("Наибольшая сумма:");
System.Console.WriteLine(" Номер строки: " + num1);
System.Console.WriteLine(" Сумма: " + bol);
System.Console.WriteLine("Наименьшая сумма:");
System.Console.WriteLine(" Номер строки: " + num2);
System.Console.WriteLine(" Сумма: " + men);
return 0;
}
static void Main()
{
Arr();
Viv();
Vic(str);
Res(str);
Console.ReadKey();
}
}
}Решение задачи: «Работа со структурой»
textual
Листинг программы
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
public const int m = 20, n = 15;
public static double[,] A = new double[m, n];
public static class str
{
public static double num1 = 1;
public static double num2 = 1;
public static double bol = 0;
public static double men = 0;
}
static int Arr()
{
for (int i = 1; i < m; i++)
{
for (int j = 1; j < n; j++)
{
A[i, j] = (i + j) / Math.Log(1 + j);
}
}
return 0;
}
static void Viv()
{
for (int i = 1; i < m; i++)
{
for (int j = 1; j < n; j++)
{
System.Console.Write(A[i, j]);
}
System.Console.WriteLine();
}
}
static int Vic()
{
double summ;
for (int i = 1; i < m; i++)
{
summ = 0;
for (int j = 1; j < n; j++)
{
summ = summ + A[i, j];
}
if (i == 1)
{
str.men = summ;
}
else
{
if (summ > str.bol)
{
str.bol = summ;
str.num1 = i;
}
if (summ < str.men)
{
str.men = summ;
str.num2 = i;
}
}
}
return 0;
}
static int Res()
{
System.Console.WriteLine("Наибольшая сумма:");
System.Console.WriteLine(" Номер строки: " + str.num1);
System.Console.WriteLine(" Сумма: " + str.bol);
System.Console.WriteLine("Наименьшая сумма:");
System.Console.WriteLine(" Номер строки: " + str.num2);
System.Console.WriteLine(" Сумма: " + str.men);
return 0;
}
static void Main()
{
Arr();
Viv();
Vic();
Res();
Console.ReadKey();
}
}
}