- 2073 Shrawan · 4 marks
Pattern: shrinking "Programming"
Short answer
Loop i=0 to 5; inner loop prints characters from index i to 10-i of the string "Programming" using putchar. Each row drops one character from both ends, yielding the shrinking pattern from "Programming" down to "a".
Write a C program to display following pattern without using formatted input/output statements.
Programming
rogrammin
ogrammi
gramm
ram
a
Each new row drops one character from the beginning and one from the end of "Programming". Row i (starting from 0) prints the characters from index i to 10 - i. The output is done with putchar() only.
#include <stdio.h>
int main(void)
{
char s[] = "Programming";
int i, j;
for (i = 0; i < 6; i++)
{
for (j = i; j < 11 - i; j++)
putchar(s[j]);
putchar('\n');
}
return 0;
}
Output:
Programming
rogrammin
ogrammi
gramm
ram
a
The outer loop runs 6 times (11 characters become 9, 7, 5, 3 and 1); the inner loop prints characters from s[i] to s[10-i].
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Pattern: PULCHOWK using unformatted output · Computer Programming, chapter 4
- Output of printf statements · Computer Programming, chapter 4
- Formatted and unformatted I/O in FORTRAN · Computer Programming, chapter 11
- Formatted vs unformatted I/O · Computer Programming, chapter 4 · asked 4×
- Formatted I/O in FORTRAN with syntax · Computer Programming, chapter 11
- Output of arithmetic expression program · Computer Programming, chapter 3
- Pyramid pattern output program · Object Oriented Programming, chapter 8
- Output of e^(−2t)u(t) to a rectangular input · Signals and Systems, chapter 5 · asked 4×
- CE configuration input/output characteristics · Basic Electronics Engineering, chapter 3 · asked 3×
- LTI output for h(t)=e^(-2t), rectangular input · Data Communication, chapter 2 · asked 3×