Number pattern

C program to display patterns using do while loop

C program to display patterns using do while loop

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

Rectangle number pattern

#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

 

Triangle number pattern

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

Rectangle star pattern

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

*******
*******
*******
*******
*******
*******
*******
*******

Triangle star pattern

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

*
* *
* * *
* * * *
* * * * *
* * * * * *

Similar post

Java program to print star pyramid pattern 

C program to print star pyramid pattern 

C++ program to print star pyramid pattern 

Python program to print star pyramid pattern 

Floyd’s triangle number pattern using for loop in C

Floyd’s triangle pattern using nested for loop in Java

Floyd’s triangle pattern using nested while loop in Java

Hollow pyramid triangle pattern in C++ language

Rhombus pattern in Java using for loop

Rhombus pattern in C using while loop

Rhombus pattern in C++ using do-while loop

 

Suggested for you

For loop in Java language

For loop in C++ language

For loop in C language

For loop in Python language

 

While loop in Java language

While loop in C language

While loop in C++ language

While loop in Python language

 

Do-while loop in Java language

Do-while loop in C language

Do-while loop in C++ language

 

Nested for loop in Java language

Nested for loop in C++ language

Nested for loop in C language

Nested for loop in Python language

 

Operator in C language

Java code to display patterns using do while loop
Cpp program to display patterns using do while loop
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

3 weeks ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago

C Program to multiplication table using Array

C Program to multiplication table using Array In this tutorial , we will discuss about…

2 months ago

Java program to check odd or even using recursion

Java program to check odd or even using recursion In this tutorial, we discuss a…

2 months ago