Работа со структурой - C#

Узнай цену своей работы

Формулировка задачи:

Добрый день! Подскажите, пожалуйста, как обратиться к конкретному элементу массива в С#. И помимо этого, в программе выдает ошибки там где вызываются функции. Помогите, пожалуйста
Листинг программы
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. namespace ConsoleApplication1
  6. {
  7. class Program
  8. {
  9. public const int m = 20, n = 15;
  10. public double[,] A = new double [m,n];
  11. public struct str{
  12. double num1=1;
  13. double num2=1;
  14. double bol=0;
  15. double men=0;}
  16. int Arr()
  17. {
  18. for (int i = 1; i < m; i++)
  19. {
  20. for (int j = 1; j < n; j++)
  21. {
  22. A[i, j] = (i + j) / Math.Log(1 + j);
  23. }
  24. }
  25. return 0;
  26. }
  27.  
  28. void Viv()
  29. {
  30. for (int i = 1; i < m; i++)
  31. {
  32. for (int j = 1; j < n; j++)
  33. {
  34. System.Console.Write(A[i, j]);
  35. }
  36. System.Console.WriteLine();
  37. }
  38. }
  39. int Vic()
  40. {
  41. double summ;
  42. for (int i = 1; i < m; i++)
  43. {
  44. summ = 0;
  45. for (int j = 1; j < n; j++)
  46. {
  47. summ = summ + A[i, j];
  48. }
  49. if (i == 1)
  50. {
  51. str->men = summ;
  52. }
  53. else
  54. {
  55. if (summ > bol)
  56. {
  57. bol = summ;
  58. num1 = i;
  59. }
  60. if (summ < men)
  61. {
  62. men = summ;
  63. num2 = i;
  64. }
  65. }
  66. }
  67. return 0;
  68. }
  69. int Res()
  70. {
  71. System.Console.WriteLine("Наибольшая сумма:");
  72. System.Console.WriteLine(" Номер строки: " + num1);
  73. System.Console.WriteLine(" Сумма: " + bol);
  74. System.Console.WriteLine("Наименьшая сумма:");
  75. System.Console.WriteLine(" Номер строки: " + num2);
  76. System.Console.WriteLine(" Сумма: " + men);
  77. return 0;
  78. }
  79. static void Main()
  80. {
  81. Arr();
  82. Viv();
  83. Vic(str);
  84. Res(str);
  85. Console.ReadKey();
  86. }
  87. }
  88. }

Решение задачи: «Работа со структурой»

textual
Листинг программы
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ConsoleApplication1
  7. {
  8.     class Program
  9.     {
  10.         public const int m = 20, n = 15;
  11.         public static double[,] A = new double[m, n];
  12.         public static class str
  13.         {
  14.             public static double num1 = 1;
  15.             public static double num2 = 1;
  16.             public static double bol = 0;
  17.             public static double men = 0;
  18.         }
  19.  
  20.         static int Arr()
  21.         {
  22.             for (int i = 1; i < m; i++)
  23.             {
  24.  
  25.                 for (int j = 1; j < n; j++)
  26.                 {
  27.  
  28.                     A[i, j] = (i + j) / Math.Log(1 + j);
  29.                 }
  30.             }
  31.             return 0;
  32.         }
  33.  
  34.  
  35.         static void Viv()
  36.         {
  37.             for (int i = 1; i < m; i++)
  38.             {
  39.  
  40.                 for (int j = 1; j < n; j++)
  41.                 {
  42.  
  43.                     System.Console.Write(A[i, j]);
  44.                 }
  45.                 System.Console.WriteLine();
  46.             }
  47.         }
  48.  
  49.         static int Vic()
  50.         {
  51.             double summ;
  52.             for (int i = 1; i < m; i++)
  53.             {
  54.                 summ = 0;
  55.                 for (int j = 1; j < n; j++)
  56.                 {
  57.                     summ = summ + A[i, j];
  58.                 }
  59.                 if (i == 1)
  60.                 {
  61.                     str.men = summ;
  62.                 }
  63.                 else
  64.                 {
  65.                     if (summ > str.bol)
  66.                     {
  67.                         str.bol = summ;
  68.                         str.num1 = i;
  69.                     }
  70.                     if (summ < str.men)
  71.                     {
  72.                         str.men = summ;
  73.                         str.num2 = i;
  74.                     }
  75.                 }
  76.             }
  77.             return 0;
  78.         }
  79.  
  80.         static int Res()
  81.         {
  82.             System.Console.WriteLine("Наибольшая сумма:");
  83.             System.Console.WriteLine("   Номер строки: " + str.num1);
  84.             System.Console.WriteLine("   Сумма: " + str.bol);
  85.             System.Console.WriteLine("Наименьшая сумма:");
  86.             System.Console.WriteLine("   Номер строки: " + str.num2);
  87.             System.Console.WriteLine("   Сумма: " + str.men);
  88.             return 0;
  89.         }
  90.  
  91.         static void Main()
  92.         {
  93.             Arr();
  94.             Viv();
  95.             Vic();
  96.             Res();
  97.  
  98.             Console.ReadKey();
  99.         }
  100.     }
  101. }

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

11   голосов , оценка 4.364 из 5

Нужна аналогичная работа?

Оформи быстрый заказ и узнай стоимость

Бесплатно
Оформите заказ и авторы начнут откликаться уже через 10 минут