Print star pattern in C++

to print pattern in c++ Print pattern in C++

Program to print star patterns in c++ language.

In this program, we are going to print the star pattern. This program also increases our understanding of the use of the loop. I'm using for loop to do so, for loop is recommended to make pattern programs.

Pattern program can also take input from the user to decide the length and breadth of the pattern but I'm not taking these inputs from the user.

Source code to print star pattern:

#include<iostream.h>
#include<conio.h>
void main()
{
     clrscr();
     int i,j;
     for(i=0;i<=5;i++)
    {
    for(j=0;j<i;j++)
   {
   cout<<“*”;
   }
   cout<<“\n”;
   }
getch();
}

I'm using "i" and "j" as loop variables, you can take any another variable also according to your choice. You can also edit this program according to your choice. If you fall in an error then comment below. I try to solve as soon as possible or you can also dm me on insta.

Program to print reverse star pattern in c++ language.


Output:-


Print pattern in C++
Print pattern in C++
 


#include<iostream.h>
#include<conio.h>
void main()
{
     clrscr();
     int i,j;
     for(i=5;i>=5;i--)
    {
    for(j=0;j<i;j++)
   {
   cout<<“*”;
   }
   cout<<“\n”;
   }
getch();
}

About this Program:-

To print patterns in c++ we use nested for loop. The inner loop is used to print "*" in the same line while the outer loop is used for a new line. You should also try to make a diamond pattern in c language to strengthen pattern programming.
In interviews, they can also ask you to make pattern programs. 


Post a Comment

Please do not enter any spam link in the comment box.