fork download
  1. using System;
  2.  
  3. public class Test
  4. {
  5. public static void Main()
  6. {
  7. new Test().button1_Click(null, null);
  8. }
  9.  
  10. int rc;
  11. double centro, centro1;
  12. int r2, c2, rc2;
  13. private void button1_Click(object sender, EventArgs e)
  14. {
  15.  
  16. try
  17. {
  18. string textBoxContents = "9";
  19. rc = Convert.ToInt16(textBoxContents);
  20. if (rc == 3 || rc == 5 || rc == 7 || rc == 9 || rc == 11)
  21. {
  22. centro = rc / 2;
  23. centro1 = Math.Round(centro, 0);
  24. int[,] dim = new int[rc, rc];
  25. int v = 1, r = 0, c, x = 0;
  26. c = Convert.ToInt16(centro1);
  27. //rc2 = rc;
  28. for (x = 0; x < (rc*rc); x++)
  29. {
  30. if (dim[r, c] >= 1)
  31. {
  32. r = r2 + 2;
  33. c = c2 - 1;
  34. dim[r, c] = v;
  35. }
  36. else
  37. {
  38. dim[r, c] = v;
  39. }
  40. c++;
  41. r--;
  42. v++;
  43. if (r < 0)
  44. {
  45. r = rc -1;
  46. };
  47. if (c > (rc-1))
  48. {
  49. c = 0;
  50. };
  51. r2 = r;
  52. c2 = c;
  53.  
  54. }
  55. string matrixString = "";
  56. for (int i = 0; i < dim.GetLength(0); i++)
  57. {
  58. for (int j = 0; j < dim.GetLength(1); j++)
  59. {
  60. matrixString += dim[i, j].ToString();
  61. matrixString += " ";
  62. }
  63.  
  64. matrixString += Environment.NewLine;
  65. }
  66. Console.WriteLine(matrixString);
  67. }
  68. else
  69. {
  70. Console.WriteLine("***Else*** Verifica que:\n- Introduzcas solo digitos.\n- Introduzcas solo numeros inpares\ndentro de las demensiones indicadas.\n- Solo introduzcas el numero de\nrenglones o columnas.");
  71. }
  72. }
  73.  
  74. catch
  75. {
  76. Console.WriteLine("***Exception*** Verifica que:\n- Introduzcas solo digitos.\n- Introduzcas solo numeros inpares\ndentro de las demensiones indicadas.\n- Solo introduzcas el numero de\nrenglones o columnas.");
  77. }
  78. }
  79.  
  80. }
  81.  
Success #stdin #stdout 0.03s 24144KB
stdin
Standard input is empty
stdout
***Exception***   Verifica que:
- Introduzcas solo      digitos.
- Introduzcas solo numeros inpares
dentro de las demensiones indicadas.
- Solo introduzcas el numero de
renglones o columnas.