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
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 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 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 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 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 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 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 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 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 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 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 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
How to find reverse number using method In this article, we will discuss the concept…
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…
Program to count vowels, consonants, words, characters and space in Java In this article, we…
How to print multiplication table using Array in C++ language In this post, we will…
C Program to multiplication table using Array In this tutorial , we will discuss about…