---
title: "Pattern N, eee, PPPPP using unformatted I/O"
subject: "Computer Programming"
chapter: 4
key: "semester_1/computer_programming:pattern-n-e-p-a-l"
source: https://www.bctengineer.com/q/semester_1/computer_programming/pattern-n-e-p-a-l
site: BCT Engineering
---

# Pattern N, eee, PPPPP using unformatted I/O

Computer Programming · Chapter 4: Input and Output

- Asked in: 2074 Asoj, 5 marks
- Video: ['pulchowk' pattern using unformatted input output |C programming|](https://www.youtube.com/watch?v=jWCeFXV2qlk) — THE SPORTING TECHIE
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_1/computer_programming/pattern-n-e-p-a-l
- Whole chapter: https://www.bctengineer.com/md/semester_1/computer_programming/chapter-4

## Question

Write a program in C to generate following pattern using unformatted input/output functions only.
```
      N
    e e e
  P P P P P
 a a a a a a a
L L L L L L L L L
```

## Short answer

Using only putchar, loop row from 1 to 5: print (5-row) pairs of spaces, then (2*row-1) copies of the letter from array {'N','e','P','a','L'} each followed by a space, and a newline. This produces the centered triangular pattern.

## Answer

Only `putchar()` is used for output (unformatted), row `r` contains `2r - 1` copies of one letter, and each row is preceded by blanks to make a triangle.

```c
#include <stdio.h>
int main(void)
{
    char letters[] = {'N', 'e', 'P', 'a', 'L'};
    int row, k;
    for (row = 1; row <= 5; row++)
    {
        for (k = 1; k <= 5 - row; k++)      /* leading blanks */
        {
            putchar(' ');
            putchar(' ');
        }
        for (k = 1; k <= 2 * row - 1; k++)  /* letter and a space */
        {
            putchar(letters[row - 1]);
            putchar(' ');
        }
        putchar('\n');
    }
    return 0;
}
```
Output:
```text
        N 
      e e e 
    P P P P P 
  a a a a a a a 
L L L L L L L L L
```

#### Explanation
- The outer loop runs once per row (5 rows) and picks the letter from the array.
- The first inner loop prints `5 - row` pairs of blanks, which shifts the row to the right.
- The second inner loop prints `2*row - 1` letters, each followed by a blank.
- The number of letters in the rows is 1, 3, 5, 7, 9.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. How many copies of the letter does row r contain?
   A. r
   B. 2r - 1
   C. 2r
   D. r + 1
   Answer: B. Rows have 1, 3, 5, 7, 9 letters. (Key point: Letters per row)

2. How many pairs of blanks precede row r?
   A. r
   B. r - 1
   C. 5 - r
   D. 2r
   Answer: C. 5 - row pairs shift the triangle to the right. (Key point: Leading blanks)

3. Which function is used for output?
   A. printf()
   B. putchar()
   C. scanf()
   D. fprintf()
   Answer: B. Only putchar is used, being unformatted. (Key point: Unformatted)

4. What ends each row?
   A. putchar('\n')
   B. putchar(' ')
   C. break
   D. return
   Answer: A. A newline moves to the next row. (Key point: Newline)

## Related in Computer Programming

- [Pattern: PULCHOWK using unformatted output](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Apattern-pulchowk) — Computer Programming, chapter 4
- [Formatted vs unformatted I/O](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Aformatted-vs-unformatted-io) — Computer Programming, chapter 4, asked 4×
- [Formatted and unformatted I/O in FORTRAN](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afortran-formatted-unformatted-io) — Computer Programming, chapter 11
- [Output of arithmetic expression program](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Aoutput-expression-xyz) — Computer Programming, chapter 3
- [Pattern: shrinking "Programming"](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Apattern-programming-shrinking) — Computer Programming, chapter 4

## Related in other subjects

- [Pyramid pattern output program](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Apyramid-program) — Object Oriented Programming, chapter 8
- [3-input XNOR using NOR gates only](https://www.bctengineer.com/question.md?key=semester_3%2Fdigital_logic%3Athree-input-xnor-nor) — Digital Logic, chapter 2
- [2-input XOR using NOR gates only](https://www.bctengineer.com/question.md?key=semester_3%2Fdigital_logic%3Axor-using-nor-only) — Digital Logic, chapter 2, asked 2×
- [3-input XOR using NAND gates only](https://www.bctengineer.com/question.md?key=semester_3%2Fdigital_logic%3Athree-input-xor-nand) — Digital Logic, chapter 2, asked 2×
