Number pattern

Cpp program to display patterns using do while loop

Cpp program to display patterns using do while loop

In this tutorial, we will discuss the concept of Cpp program to display patterns using do while loop.

In Cpp 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 Cpp language.

Program 1

Rectangle number pattern

#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
    int i=0;
    do{
        int j=1;
        while(j<=7)
        {
           cout<<j;
            j++;
        }
        cout<<"\n";
        i++;
    }
    while(i<=7);
    getch();
    return 0;
}

When the above code is compiled and executed, it produces the following results

1234567
1234567
1234567
1234567
1234567
1234567
1234567
1234567

Program 2

Rectangle star pattern

#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
    int i=0;
    do{
        int j=1;
        while(j<=7)
        {
           cout<<"*";
            j++;
        }
        cout<<"\n";
        i++;
    }
    while(i<=7);
    getch();
    return 0;
}

When the above code is compiled and executed, it produces the following results

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

 

Program 3

Triangle number pattern

#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
    int row=1,column=1;
    int i;
    do{
    do{
            i--;
        }while(i>=row);
        column=1;
        do{
                cout<<column;
                cout<<" ";
        column++;
    }while(column<=row);
            cout<<"\n";
            row++;
    }while(column<=8);
    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
1 2 3 4 5 6 7
1 2 3 4 5 6 7 8

 

 

 

Program 3

Triangle star pattern

#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
    int row=1,column=1;
    int i;
    do{
    do{
            i--;
        }while(i>=row);
        column=1;
        do{
                cout<<"*";
                cout<<" ";
        column++;
    }while(column<=row);
            cout<<"\n";
            row++;
    }while(column<=8);
    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 Cpp language

C program to display patterns using do while loop
Reverse order number pattern in C using for 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

PHP Star Triangle pattern program

PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…

6 months ago

PHP Full Pyramid pattern program

PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…

6 months ago

5 methods to add two numbers in Java

5 methods to add two numbers in Java In this tutorial, we will discuss the…

6 months ago

Python Full Pyramid star pattern program

Python full Pyramid star pattern program In this tutorial, we will discuss  the concept of…

9 months ago

Write a function or method to convert C into F -Entered by user

Write a function or method to convert C into F -Entered by the user In…

1 year ago

How to write a function or method to convert Celsius into Fahrenheit

How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…

1 year ago