In this tutorial, we will discuss the concept of C program to display patterns using do while loop.
In C language, we can use for loop, while loop, do-while loop to display various number, star, alphabet and binary number patterns
In this topic, we demonstrate how to display print some number and star patterns using the nested do-while loop in C language.
Program 1
#include <stdio.h> #include <stdlib.h> int main() { int i=0; do{ int j=1; while(j<=8){ printf("%d",j); j++; } printf("\n"); i++; } while(i<=6); getch(); return 0; }
When the above code is compiled and executed, it produces the following results
12345678 12345678 12345678 12345678 12345678 12345678
Program 2
#include <stdio.h> #include <stdlib.h> int main() { int row=1,column=1; int i; do{ i=8; do{ i--; }while(i>=row); column=1; do{ printf("%d",column); printf(" "); column++; }while(column<=row); printf("\n"); row++; }while(column<=6); getch(); return 0; }
When the above code is compiled and executed, it produces the following results
1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 1 2 3 4 5 6
Program 3
#include <stdio.h> #include <stdlib.h> int main() { int i=0; do{ int j=1; while(j<=7) { printf("*"); j++; } printf("\n"); i++; } while(i<=7); getch(); return 0; }
When the above code is compiled and executed, it produces the following results
******* ******* ******* ******* ******* ******* ******* *******
Program4
#include <stdio.h> #include <stdlib.h> int main() { int row=1,column=1; int i; do{ i=8; do{ i--; }while(i>=row); column=1; do{ printf("*"); printf(" "); column++; }while(column<=row); printf("\n"); row++; }while(column<=6); getch(); return 0; }
When the above code is compiled and executed, it produces the following results
* * * * * * * * * * * * * * * * * * * * *
Suggested for you
Do-while loop in C language
PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…
PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…
5 methods to add two numbers in Java In this tutorial, we will discuss the…
Python full Pyramid star pattern program In this tutorial, we will discuss the concept of…
Write a function or method to convert C into F -Entered by the user In…
How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…