Advertisement
Guest User

Untitled

a guest
Jan 21st, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApplication14
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. Console.WriteLine("Введите n > 0");
  14. int n = GetNumber();
  15. Console.WriteLine("Введите длину столбца");
  16. int row = GetNumber();
  17. int col = (n / row) + 1;
  18. int[,] array = new int[row, col];
  19. int i = 0, j = 0, temp = 1;
  20. while (i < col)
  21. {
  22. while (j < row)
  23. {
  24. if (temp <= n)
  25. array[j,i] = temp;
  26. else array[j, i] = -1;
  27. temp++;
  28. j++;
  29. }
  30. i++;
  31. j--;
  32. if (i >= col)
  33. break;
  34. while (j >= 0)
  35. {
  36. if (temp <= n)
  37. array[j, i] = temp;
  38. else array[j, i] = -1;
  39. temp++;
  40. j--;
  41. }
  42. i++;
  43. j++;
  44.  
  45. }
  46. for (int f = 0; f < row; f++)
  47. {
  48. Console.WriteLine();
  49. for (int k = 0; k < col; k++)
  50. Console.Write(array[f, k] + " ");
  51. }
  52. Console.Read();
  53.  
  54.  
  55. }
  56.  
  57. private static int GetNumber()
  58. {
  59. string data = Console.ReadLine();
  60. int f = 0;
  61. while (true)
  62. {
  63. if (Int32.TryParse(data, out f))
  64. if (Int32.Parse(data) > 0)
  65. break;
  66. else Console.WriteLine("Введите число больше 0");
  67. else Console.WriteLine("Введите число");
  68. data = Console.ReadLine();
  69. }
  70. return Int32.Parse(data);
  71. }
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement