fork download
  1. #include <stdio.h>
  2.  
  3. // ungleich Null, wenn Koordinate (x,y) Teil eines Kreuzes der Größe size * size ist
  4. int is_cross(unsigned x, unsigned y, unsigned size)
  5. {
  6. // Ränder
  7. if (x == 0 || y == 0 || x == size - 1 || y == size - 1)
  8. return 1;
  9.  
  10. // Mittleres Kreuz
  11. unsigned mitte = (size - 1) / 2;
  12. if (x == mitte || x == mitte + 1 || y == mitte || y == mitte + 1)
  13. return 1;
  14.  
  15. // Alles andere gehört nicht zum Kreuz
  16. return 0;
  17. }
  18.  
  19. int main(void)
  20. {
  21. for(int i = 0; i < 5; ++i)
  22. {
  23. unsigned size;
  24. scanf("%u", &size);
  25.  
  26. // Systematisch alle Felder durchgehen
  27. for(unsigned y = 0; y < size; ++y)
  28. {
  29. for(unsigned x = 0; x < size; ++x)
  30. {
  31. // jedes Feld passend malen
  32. if(is_cross(x, y, size))
  33. putchar('+');
  34. else
  35. putchar(' ');
  36. }
  37. putchar('\n');
  38. }
  39. putchar('\n');
  40. }
  41. return 0;
  42. }
  43.  
Success #stdin #stdout 0s 2252KB
stdin
6 8 10 12 14
stdout
++++++
+ ++ +
++++++
++++++
+ ++ +
++++++

++++++++
+  ++  +
+  ++  +
++++++++
++++++++
+  ++  +
+  ++  +
++++++++

++++++++++
+   ++   +
+   ++   +
+   ++   +
++++++++++
++++++++++
+   ++   +
+   ++   +
+   ++   +
++++++++++

++++++++++++
+    ++    +
+    ++    +
+    ++    +
+    ++    +
++++++++++++
++++++++++++
+    ++    +
+    ++    +
+    ++    +
+    ++    +
++++++++++++

++++++++++++++
+     ++     +
+     ++     +
+     ++     +
+     ++     +
+     ++     +
++++++++++++++
++++++++++++++
+     ++     +
+     ++     +
+     ++     +
+     ++     +
+     ++     +
++++++++++++++