Advertisement
Guest User

Untitled

a guest
Feb 27th, 2020
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. char **pfeilmatrix(int seitenlaenge)
  5. {
  6. char **matrix;
  7. int i, j, mitte;
  8. if (seitenlaenge % 2 == 0)
  9. {
  10. return NULL;
  11. }
  12. mitte = seitenlaenge / 2;
  13.  
  14. if ((matrix = (char **)malloc(seitenlaenge * sizeof(char *))) == NULL)
  15. {
  16. return NULL;
  17. }
  18.  
  19.  
  20. for (i = 0; i < seitenlaenge; i++)
  21. {
  22. if ((*(matrix + i) = (char *)malloc(seitenlaenge * sizeof(char))) == NULL)
  23. {
  24. return NULL;
  25. }
  26. }
  27.  
  28. for (i = 0; i < seitenlaenge; i++)
  29. {
  30. for(j = 0; j < seitenlaenge; j++)
  31. {
  32. if (j <= mitte && ((i <= mitte && i + j == mitte) || (i > mitte && i - j == mitte)))
  33. {
  34. *(*(matrix + i) + j) = 'x';
  35. }
  36. else
  37. {
  38. *(*(matrix + i) + j) = 'a';
  39. }
  40. }
  41. }
  42.  
  43. return matrix;
  44. }
  45.  
  46. int main()
  47. {
  48. int i, j;
  49. char matrixA[5][5]= {'a', 'b', 'c', 'd', 'e',
  50. 'f', 'g', 'h', 'i', 'j',
  51. 'k', 'l', 'm', 'n', 'o',
  52. 'p', 'q', 'r', 's', 't',
  53. 'u', 'v', 'w', 'x', 'y'
  54. };
  55.  
  56. char **ptrMatrix = pfeilmatrix(5);
  57.  
  58. for (i = 0; i < 5; i++)
  59. {
  60. for (j = 0; j < 5; j++)
  61. {
  62. printf("%c \t", *(*(ptrMatrix + i) + j));
  63. }
  64. printf("\n");
  65. }
  66.  
  67. return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement