C code to Alphabet triangle pattern using do-while loop
- Home
- Alphabet Pattern
- C code to Alphabet triangle pattern using do-while loop
- On
- By
- 0 Comment
- Categories: Alphabet Pattern, Floyd's triangle
C code to Alphabet triangle pattern using do-while loop
C code to Alphabet triangle pattern using the do-while loop
In this article, we will discuss the concept of C code to Alphabet triangle pattern using the do-while loop in C programming language
We can print various type of number, asterisk, binary patterns using for, while and do-while loop in C language
In this post, we will discuss how to write a program to print different alphabet triangle pattern using the do-while loop in C language.
To understand this example programs, you should have previous knowledge of following Java topics
Nested do while loop in C language
C code to Alphabet triangle pattern
Program to Alphabet triangle pattern 1
Program 1
#include <stdio.h> #include <stdlib.h> int main() { int rows; printf("Alphabet pattern\n"); printf("Enter the number of rows\n"); //Takes input from the user to number of rows scanf("%d",&rows); printf("\n"); int i,j; i=1; do{//outer loop j=1; do{//inner loop printf("%c",'A'-1+i); j++; }while(j<=i); printf("\n"); i++; }while(i<=rows); getch(); return 0; }
When the above code is executed, it produces the following results
Program to Alphabet triangle pattern 2
Program 2
#include <stdio.h> #include <stdlib.h> int main() { int i,j,rows; printf("Enter the number of rows: "); //Takes input from the user to number of rows scanf("%d",&rows); printf("\n"); i=rows; do{//outer loop j=i; do {//inner loop printf("%c",'A'-1+j); j--; }while(j>=1); i--; printf("\n"); }while(i>=1); getch(); return 0; }
When the above code is executed, it produces the following results
Program to Alphabet triangle pattern 3
Program 3
#include <stdio.h> #include <stdlib.h> int main() { int i,j,rows; printf("Alphabet pattern\n\n"); printf("Enter the number of rows\n"); //Takes input from the user to number of rows scanf("%d",&rows); i=1; do{ j=rows; do{ printf("%c",'A'-1+i); j--; }while(j>=i); printf("\n"); i++; }while(i<=rows); getch(); return 0; }
When the above code is executed, it produces the following results
Program to Alphabet triangle pattern 4
Program 4
#include <stdio.h> #include <stdlib.h> int main() { int i,j,rows; printf("Alphabet pattern \n\n"); printf("Enter number of rows\n"); //Takes input from the user to number of rows scanf("%d",&rows); printf("\n"); i=1; do{ j=1; do{ printf("%c",'A'+j-1); j++; }while(j<=i); printf("\n"); i++; }while(i<=rows); getch(); return 0; }
When the above code is executed, it produces the following results
Program to Alphabet triangle pattern 5
Program 5
#include <stdio.h> #include <stdlib.h> int main() { int i,j,rows; printf("Alphabet pattern 1\n\n"); printf("Enter the number of rows\n\n"); //Takes input from the user to number of rows scanf("%d",&rows); printf("\n"); i=rows; do{ j=i; do{ printf("%c",'A'+j-1); j++; }while( j<=rows); printf("\n"); i--; }while( i>=1); getch(); return 0; }
When the above code is executed, it produces the following results
Program to Alphabet triangle pattern 6
Program 6
#include <stdio.h> #include <stdlib.h> int main() { printf("Alphabet pattern \n\n"); printf("Enter the number of rows \n\n"); //Takes input from the user for number of rows int i,j,rows; scanf("%d",&rows); i=rows; do{ j=1; do{ printf("%c",'A'+j-1); j++; }while( j<=i); printf("\n"); i--; }while( i>=1); getch(); return 0; }
When the above code is executed, it produces the following results
Program to Alphabet triangle pattern 7
Program 7
#include <stdio.h> #include <stdlib.h> int main() { int i,j,rows; printf("Enter the number of rows\n"); //Takes input from the user for number of rows scanf("%d",&rows); printf("your pattern here\n"); i=1; do{ j=i; do{ printf("%c",(char)(j+64)); j++; }while(j<=rows); i++; printf("\n"); }while(i<=rows); getch(); return 0; }
When the above code is executed, it produces the following results
Program to Alphabet triangle pattern 8
Program 8
#include <stdio.h> #include <stdlib.h> int main() { int i,j,rows; char ch='A'; printf("Enter the number of rows: \n"); //Takes input from the user for number of rows scanf("%d",&rows); i=1; do{ j=1; do{ printf("%c ",ch++); j++; }while(j<=i); printf("\n"); i++; }while(i<=rows); getch(); return 0; }
When the above code is executed, it produces the following results
Program to Alphabet triangle pattern 9
Program 9
#include <stdio.h> #include <stdlib.h> int main() { int i,j,rows,num,count; printf("Enter the number of rows: \n"); //Takes input from the user for number of rows scanf("%d",&rows); i=1; while(i<=rows){ num=rows-1; count=i; j=1; do{ printf("%2c",(char)(count+64)); count=count+num; num--; j++; } while( j<=i); printf("\n"); i++; } getch(); return 0; }
When the above code is executed, it produces the following results
Program to Alphabet triangle pattern 10
Program 10
#include <stdio.h> #include <stdlib.h> int main() { int i,j,k,rows; printf("Enter the number of rows\n"); //Takes input from the user for number of rows scanf("%d",&rows); i=rows; do{ k=i; j=1; do{ printf("%c",(char)(k+64)); j++; k++; }while(j<=i); printf("\n"); i--; }while(i>=1); getch(); return 0; }
When the above code is executed, it produces the following results
Program to Alphabet triangle pattern 11
Program 11
#include <stdio.h> #include <stdlib.h> int main() { int i,j,k,rows; printf("Enter the number of rows\n"); //Takes input from the user for number of rows scanf("%d",&rows); i=1; do{ j=1; do{ printf(" "); j++; }while(j<=rows-i+1); k=1; do{ printf("%c",(char)(k+64)); k++; } while(k<=i); printf("\n"); i++; }while(i<=rows); getch(); return 0; }
When the above code is executed, it produces the following results
Program to Alphabet triangle pattern 12
Program 12
#include <stdio.h> #include <stdlib.h> int main() { int i,j,k,rows; printf("Enter the number of rows\n"); //Takes input from the user for number of rows scanf("%d",&rows); i=1; do{ j=1; do{ printf(" "); j++; }while(j<=rows-i); k=1; do{ printf("%c",(char)(j+64)); k++; }while(k<=i); printf("\n"); i++; } while(i<=rows); getch(); return 0; }
When the above code is executed, it produces the following results
Suggested for you
Similar post
C code to Alphabet triangle pattern using the do-while loop
C++ code to Alphabet triangle pattern using the do-while loop
Java code to Alphabet triangle pattern using the do-while loop
Alphabet triangle pattern in C language
Alphabet triangle pattern in C language using while loop
Alphabet triangle pattern in Java language
Alphabet triangle pattern in Java language using while loop
Alphabet triangle pattern in C++ language
Alphabet triangle pattern in C++ language using while loop