Skip to main content

Pattern: PULCHOWK using unformatted output

Short answer

Store the exact row strings {"P","Pu","PuL","PULC","PuLcH","PULCHO","puLcHoW","PULCHOWK"} in a pointer array. For each row, use putchar in a loop to print each character, then a newline. The output matches the given mixed-case staircase pattern.

Write a C program to display following pattern using unformatted output statements:

P
Pu
PuL
PULC
PuLcH
PULCHO
puLcHoW
PULCHOWK

The rows follow no single arithmetic rule for the upper/lower case, so they are stored as they are shown and printed character by character with putchar() (unformatted output). Row i has i + 1 characters, so the pattern grows by one letter per row.

#include <stdio.h>
int main(void)
{
    const char *row[8] = {"P", "Pu", "PuL", "PULC", "PuLcH",
                          "PULCHO", "puLcHoW", "PULCHOWK"};
    int i, j;
    for (i = 0; i < 8; i++)
    {
        for (j = 0; row[i][j] != '\0'; j++)
            putchar(row[i][j]);
        putchar('\n');
    }
    return 0;
}

Output:

P
Pu
PuL
PULC
PuLcH
PULCHO
puLcHoW
PULCHOWK

Explanation

  • row[8] holds the eight lines of the pattern.
  • The outer loop selects a row; the inner loop runs until the string terminator '\0' and prints each character using putchar().
  • putchar('\n') moves to the next line after each row.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Computer Programming chapter 4 questions →