C Program
C program to Print B star pattern Asterisks pattern
Example:-
This C Program Print a pattern in the shape of the capital letter B using asterisks "*"
Explain Program
Step :1
#include <stdio.h>
standard input/output library for using
functions like printf().
Step :2
int main() {
int a, b;
int rows = 7;
a and b are loop counters.
rows = 7 sets the height of the pattern to 7 rows. This will
determine how tall the printed "E" is.
Step :3
for (a = 0; a < rows; a++) {
Step :4
for (a = 0; a < rows; a++) {
Step :5
if (
b == 0 ||
(a == 0
&& b < 4) ||
(a == rows
/ 2 && b < 4) ||
(a == rows
- 1 && b < 4) ||
(b == 4
&& a != 0 && a != rows / 2 && a != rows - 1)
) {
printf("*");
} else {
printf(" ");
}
b == 0s prints the left vertical line of the "E".
(a == 0 && b
< 4)
draws the top horizontal bar of the "E".
(a == rows / 2
&& b < 4)
draws the middle horizontal bar.
(a == rows - 1 && b < 4)
draws the bottom horizontal bar.
(b == 4 && a
!= 0 && a != rows / 2 && a != rows - 1)
adds a small vertical extension on the top right.
No comments:
Post a Comment