Alphabet Pattern (A-Z) in c programming
Alphabet Pattern Printing in C: A-Z with Examples
Creating alphabet patterns in C for all the letters of the alphabet would involve writing specific code for each letter. Below, I'll provide a list of patterns for a few letters ('A', 'B', 'C', 'D', and 'E') to give you an idea. You can follow a similar approach for other letters.
Pattern for 'A':
#include <stdio.h>
int main() {
int i, j, n;
printf("Enter the number of rows (odd): ");
scanf("%d", &n);
// Upper part of the 'A'
for(i = 0; i < n/2 + 1; i++) {
for(j = 0; j < (2*n); j++) {
if(j >= n-i && j <= n+i)
printf("*");
else
printf(" ");
}
printf("\n");
}
// Lower part of the 'A'
for(i = 0; i < n/2; i++) {
for(j = 0; j < (2*n); j++) {
if(j == n || j == (2*n)-1-n || (i == n/2-1 && j > n && j < (2*n)-1-n))
printf("*");
else
printf(" ");
}
printf("\n");
}
return 0;
}
Pattern for 'B':
#include <stdio.h>
int main() {
int i, j, n;
printf("Enter the number of rows: ");
scanf("%d", &n);
// Upper part of the 'B'
for(i = 0; i < n; i++) {
printf("*");
for(j = 0; j < n; j++) {
if((i == 0 || i == n/2 || i == n-1) && j < n-1)
printf("*");
else if(j == n-1 && !(i == 0 || i == n/2 || i == n-1))
printf("*");
else
printf(" ");
}
printf("\n");
}
return 0;
}
Pattern for 'C':
#include <stdio.h>
int main() {
int i, j, n;
printf("Enter the number of rows: ");
scanf("%d", &n);
for(i = 0; i < n; i++) {
printf("*");
for(j = 0; j < n-1; j++) {
if((i == 0 || i == n-1) && j < n-2)
printf("*");
else if(i > 0 && i < n-1 && j == 0)
printf("*");
else
printf(" ");
}
printf("\n");
}
return 0;
}
Pattern for 'D':
#include <stdio.h>
int main() {
int i, j, n;
printf("Enter the number of rows: ");
scanf("%d", &n);
for(i = 0; i < n; i++) {
printf("*");
for(j = 0; j < n-1; j++) {
if(j == n-2 && !(i == 0 || i == n-1) || (i == 0 || i == n-1) && j < n-2)
printf("*");
else
printf(" ");
}
printf("\n");
}
return 0;
}
Pattern for 'E':
#include <stdio.h>
int main() {
int i, j, n;
printf("Enter the number of rows: ");
scanf("%d", &n);
for(i = 0; i < n; i++) {
printf("*");
for(j = 0; j < n-1; j++) {
if((i == 0 || i == n/2 || i == n-1) && j < n-2)
printf("*");
else
printf(" ");
}
printf("\n");
}
return 0;
}
These are just a few examples. You can use similar logic to create patterns for other letters. Remember to adjust the loop conditions and positions of stars based on the desired shape of each letter.