Advertisement
Guest User

Untitled

a guest
Nov 14th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3.  
  4. using namespace std;
  5.  
  6. void main()
  7. {
  8. int x = 5;
  9. int y = 8;
  10.  
  11. int **arr = (int**)calloc(y, sizeof(int*));
  12.  
  13. for (int i = 0; i < y; ++i)
  14. {
  15. arr[i] = (int*)calloc(x, sizeof(int));
  16. }
  17.  
  18. int k = 1;
  19. int d = 0;
  20.  
  21. while(k <=x*y)
  22. {
  23. for (int i = 0+d; i < x-d; ++i)
  24. {
  25. arr[d][i] = k++;
  26. }
  27. for (int i = d+1; i < y-d; ++i)
  28. {
  29. arr[i][x - 1 - d] = k++;
  30. }
  31. for (int i = x-2-d; i >= d ; --i)
  32. {
  33. arr[y-1-d][i] = k++;
  34. }
  35. for (int i = y - 2 - d; i >= d+1; --i)
  36. {
  37. arr[i][d] = k++;
  38. }
  39. ++d;
  40. }
  41.  
  42.  
  43. for (int i = 0; i < y; ++i)
  44. {
  45. for (int j = 0; j < x; ++j)
  46. {
  47. printf("%2d ", arr[i][j]);
  48. }
  49. printf("\n");
  50. }
  51.  
  52. system("pause");
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement