Advertisement
Guest User

Untitled

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