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