Codeforcoding

C++ Program to Alphabet triangle pattern using do-while loop

C++ program to Alphabet triangle pattern using the do-while loop

In this article, we will discuss the concept of C++ program to Alphabet triangle pattern using the do-while loop

We can print various type of number, asterisk, binary patterns using for, while and do-while loop in C++ programming 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 C++ topics

Do while loop in C++ language

Nested do while loop in C++ language

Code to Alphabet triangle pattern 1

Program 1

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

int main()
{
    int i,j,rows;
    cout << "Enter the number of rows:" << endl;
//get input from the user for number of rows
    cin>>rows;
    cout<<"\n";
    cout<<"Here, your pattern\n";

    i=rows;
    do{
            j=1;
       do{
        cout<<((char)(j+64));
    j++;
    } while( j<=i);
    cout<<"\n";
    i--;
    }while( i>=1);
    getch();
    return 0;
}

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

C++ code to Alphabet triangle pattern using do-while loop
Alphabet pattern 1

Code to Alphabet triangle pattern 2

Program 2

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

int main()
{
    int i,j,rows;
    cout << "Enter the number of rows" << endl;
//get input from the user for number of rows
    cin>>rows;
   cout<<"\n";
    i=1;
   do{
        j=1;
    do{
        cout<<(char)(j+64);
        j++;
    }while(j<=i);
    i++;
    cout<<"\n";
    }while(i<=rows);
getch();
    return 0;
}

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

Alphabet pattern 2

 

Code to Alphabet triangle pattern 3

Program 3

 

#include <iostream>
#include <conio.h>

using namespace std;

int main()
{
    int i,j,rows;
    cout << "Enter the number of rows" << endl;
//get input from the user for number of rows
    cin>>rows;
     cout<<"\n";
    i=rows;
    do{
        j=i;
        do{
          cout<<((char)(j+64));
          j--;
        }while(j>=1);
        i--;
        cout<<"\n";
    }while(i>=1);
getch();

    return 0;
}

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

Alphabet pattern 3

Code to Alphabet triangle pattern 4

Program 4

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

int main()
{
    int i,j,k,rows;

    cout << "Enter the number of rows" << endl;
//get input from the user for number of rows
    cin>>rows;
    cout << "\nHere your pattern\n" << endl;
    i=1;
    do{
            j=i;
        do{
            cout<<((char)(j+64));
    j++;
        }while(j<=rows);
        cout<<"\n";
        i++;
    }while( i<=rows);
    getch();
    return 0;
}

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

Alphabet pattern 4

Code to Alphabet triangle pattern 5

Program 5

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

int main()
{
    int i,j,rows;
    cout << "Enter number of rows: ";
//get input from the user for number of rows
    cin>>rows;
    cout << "\nHere your pattern\n\n";
    i=1;
   do{
            j=i;
        do{
        cout<<((char)(i+64));
     j++;
    }while(j<=rows);
    cout<< endl;
     i++;
    } while(i<=rows);
getch();
    return 0;
}

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

Alphabet pattern 5

 

 

Code to Alphabet triangle pattern 6

Program 6

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

int main()
{
    int i,j,rows;
    char ch='A';
    cout<<"Enter the number of rows: ";
//get input from the user for number of rows
    cin>>rows;
    i=1;

    do{
        j=1;
       do{
            cout<<ch++<<" ";
            j++;
        } while(j<=i);
        i++;
        cout<<"\n";
    } while(i<=rows);
    getch();
    return 0;
}

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

Alphabet pattern 6

 

Code to Alphabet triangle pattern 7

Program 7

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

int main()
{
    int i,j,rows;
    char ch='A';
    cout<<"Enter the number of rows: ";
//get input from the user for number of rows
    cin>>rows;
    i=1;

    do{
        j=1;
        do{
            cout<<((char)(j+64))<<" ";
            j++;
        }while(j<=(i*2-1));
        i++;
        cout<<"\n";
    } while(i<=rows);
    getch();
    return 0;
}

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

Alphabet pattern 7

 

Code to Alphabet triangle pattern 8

Program 8

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

int main()
{
    int i,j,rows;
    cout << "Enter number of rows: ";
//get input from the user for number of rows
    cin>>rows;
    cout << "\nHere your pattern\n\n";
    i=1;
 do{
            j=1;
       do{
        cout<<(char)(i+64);
     j++;
    } while(j<=i);
    cout<< endl;
     i++;
    } while(i<=rows);
getch();
    return 0;
}

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

Alphabet pattern 8

Code to Alphabet triangle pattern 9

Program 9

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

int main()
{
    int i,j,rows,num,count1;
    cout<<"Enter the number of rows: ";
//get input from the user for number of rows
    cin>>rows;
    i=1;

    do{
        num=rows-1;
        count1=i;

        j=1;
        do{
            cout<<(char)(count1+64)<<" ";
            count1=count1+num;
            num--;
            j++;
        }while(j<=i);
        i++;
        cout<<"\n";
    }while(i<=rows);
    getch();
    return 0;
}


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

Alphabet pattern 9

Code to Alphabet triangle pattern 10

Program 10

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

int main()
{
    int i,j,rows;
    cout << "Enter number of rows: ";
//get input from the user for number of rows
    cin>>rows;
    cout << "\nHere your pattern\n\n";
    i=rows;
  do{
            j=i;
       do{
        cout<<(char)(j+64);
     j++;
    } while(j<=rows);
    cout<< endl;
     i--;
    }while(i>=1);
getch();
    return 0;
}

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

Alphabet pattern 10

 

Code to Alphabet triangle pattern 11

Program 11

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

int main()
{
    int i,j,rows;
    cout << "Enter number of rows: ";
//get input from the user for number of rows
    cin>>rows;
    cout << "\nHere your pattern\n\n";
    i=1;
  do{
            j=i;
        do{
        cout<<(char)(j+64);
     j--;
    }while(j>=1);
    cout<< endl;
     i++;
    }while(i<=rows);
getch();
    return 0;
}

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

Alphabet pattern 11

 

 

Code to Alphabet triangle pattern 12

Program 12

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

int main()
{
    int i,j,rows;
    cout << "Enter number of rows: ";
//get input from the user for number of rows
    cin>>rows;
    cout << "\nHere your pattern\n\n";
    i=1;
  do{
            j=1;
        do{
        cout<<(char)(rows-i+1+64);
     j++;
    }while(j<=i);
    cout<< endl;
     i++;
    }while(i<=rows);
getch();
    return 0;
}

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

Alphabet pattern 12

 

Code to Alphabet triangle pattern 13

Program 13

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

int main()
{
    int i,j,rows;
    cout << "Enter number of rows: ";
//get input from the user for number of rows
    cin>>rows;
    cout << "\nHere your pattern\n\n";
    i=rows;
 do{
            j=rows;
       do{
        cout<<(char)(j+64);
     j--;
    }while(j>=i);
    cout<< endl;
     i--;
    } while(i>=1);
getch();
    return 0;
}

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

Alphabet pattern 13

 

Code to Alphabet triangle pattern 14

Program 14

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

int main()
{
    int i,j,rows;
    cout << "Enter number of rows: ";
//get input from the user for number of rows
    cin>>rows;
    cout << "\nHere your pattern\n\n";
    i=rows;
  do{
            j=1;
       do{
        cout<<(char)(i+64);
     j++;
    }while(j<=i);
    cout<< endl;
     i--;
    }while(i>=1);
getch();
    return 0;
}

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

Alphabet pattern 14

Code to Alphabet triangle pattern 15

Program 15

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

int main()
{
    int i,j,rows;
    cout << "Enter number of rows: ";
//get input from the user for number of rows
    cin>>rows;
    cout << "\nHere your pattern\n\n";
    i=1;
 do{
            j=rows;
       do{
        cout<<(char)(j+64);
     j--;
    }while(j>=i);
    cout<< endl;
     i++;
    } while(i<=rows);
getch();
    return 0;
}

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

Triangle pattern 15

 

Suggested for you

Data type in C++ language

Variable in C++ language

The operator in C++ language

Loops in C++ language

 

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

 

Alphabet triangle pattern using do-while loop in Java
Exit mobile version