- 2070 Chaitra · 7 marks
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 usingputchar(). putchar('\n')moves to the next line after each row.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Pattern N, eee, PPPPP using unformatted I/O · Computer Programming, chapter 4
- Output of printf statements · Computer Programming, chapter 4
- Pattern: shrinking "Programming" · Computer Programming, chapter 4
- Formatted and unformatted I/O in FORTRAN · Computer Programming, chapter 11
- Output of arithmetic expression program · Computer Programming, chapter 3
- Formatted vs unformatted I/O · Computer Programming, chapter 4 · asked 4×
- Pyramid pattern output program · Object Oriented Programming, chapter 8
- Assembler statements and directives · Microprocessor, chapter 3 · asked 4×
- Display 0 to 9 on seven segment · Embedded System, chapter 9 · asked 2×
- Display N characters using default arguments · Object Oriented Programming, chapter 3