fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int main() {
  5. int a, b, size = 15;
  6. char text[] = "Juthaporn";
  7. int textLength = strlen(text);
  8. int textRow = size / 2 - 1; // ขยับข้อความขึ้นมา 1 แถว
  9.  
  10. // วาดส่วนบนของหัวใจ
  11. for (a = size / 2; a <= size; a += 2) {
  12. for (b = 1; b < size - a; b += 2)
  13. printf(" ");
  14. for (b = 1; b <= a; b++)
  15. printf(b == 1 || b == a ? "B" : " ");
  16. for (b = 1; b <= size - a; b++)
  17. printf(" ");
  18. for (b = 1; b <= a; b++)
  19. printf(b == 1 || b == a ? "B" : " ");
  20. printf("\n");
  21. }
  22.  
  23. // วาดส่วนล่างของหัวใจ
  24. for (a = size; a >= 0; a--) {
  25. for (b = a; b < size; b++)
  26. printf(" ");
  27. if (a == textRow) {
  28. // ใส่ข้อความ "Juthaporn" ตรงกลาง
  29. int padding = ((a * 2) - 1 - textLength) / 2;
  30. for (b = 1; b <= (a * 2) - 1; b++) {
  31. if (b <= padding || b > padding + textLength)
  32. printf(b == 1 || b == (a * 2) - 1 ? "B" : " ");
  33. else
  34. printf("%c", text[b - padding - 1]);
  35. }
  36. } else {
  37. for (b = 1; b <= (a * 2) - 1; b++)
  38. printf(b == 1 || b == (a * 2) - 1 ? "B" : " ");
  39. }
  40. printf("\n");
  41. }
  42.  
  43. return 0;
  44. }
  45.  
Success #stdin #stdout 0.01s 5292KB
stdin
Standard input is empty
stdout
    B     B        B     B
   B       B      B       B
  B         B    B         B
 B           B  B           B
B             BB             B
B                           B
 B                         B
  B                       B
   B                     B
    B                   B
     B                 B
      B               B
       B             B
        B           B
         BJuthapornB
          B       B
           B     B
            B   B
             B B
              B