[et_pb_section fb_built=”1″ _builder_version=”4.2.2″][et_pb_row _builder_version=”4.2.2″][et_pb_column type=”4_4″ _builder_version=”4.2.2″][et_pb_text _builder_version=”4.4.2″ text_font=”Verdana||||||||” text_text_color=”#000000″ text_font_size=”16px”]

Merge two inverted triangle pattern

[/et_pb_text][et_pb_text _builder_version=”4.4.2″ text_font=”Verdana||||||||” text_text_color=”#000000″ text_font_size=”16px” custom_margin=”||-1px|||” custom_padding=”||0px|||”]

Merge two inverted triangle pattern in C- in this tutorial we will cover techniques to merging the inverted right triangle and inverted mirror right triangle side by side. Triangle Pattern is made using Star Symbol(*).

The following Pattern program is written in three unique manners:

  • For Loop
  •  While Loop
  •  Do-While Loop

[/et_pb_text][et_pb_text _builder_version=”4.4.4″ text_font=”Verdana||||||||” text_text_color=”#000000″ text_font_size=”16px”]

we have to specify a certain number of rows and columns. According to the above program number of rows specified 5 and the number of Columns specified  7.

The Star Symbol (any other symbol can take) is picked here for demonstration.

This issue can also be solved by observing that the two triangle is printed side by side.

[/et_pb_text][et_pb_text _builder_version=”4.4.2″ header_text_color=”#000000″ header_2_text_color=”#000000″]

1. Merge two inverted triangle pattern: For Loop

[/et_pb_text][et_pb_text _builder_version=”4.4.2″ text_text_color=”#000000″ text_font_size=”16px”]

 Algorithm

Input: Let, three variables say r,c,n,m. The value of n and m will be given by the user.

step 1: Input values for n and m where n is Row size and m is column size

step 2: r=1 and outer loop will be performed as long as r<=n

step 3: c=1

step 4: inner loop will be performed as long as  c<=m

step 4.1: check if (if(c<=n+1-r||c>=n-1+r)) is true then 

                               print symbol star ( “*”)

else

print  “blank space”

step 5: j=j+1

step 6: End inner loop

step 7: next line start

step 8: i= i+1

step 9:  End outer loop

[/et_pb_text][et_pb_text _builder_version=”4.2.2″ header_3_font=”Verdana|700|||||||” header_3_text_color=”#000000″]

Source Code

[/et_pb_text][et_pb_text _builder_version=”4.2.2″ text_font=”|600|||||||” text_text_color=”#000000″ border_radii=”on|8px|8px|8px|8px” border_width_all=”3px” border_style_all=”double”]

int main()
{
    int r,c,n,m;
    printf("\n\tEnter row no:");
    scanf("%d",&n);
    printf("\n\tEnter column no:");
    scanf("%d",&m);
    printf("\n\t");
    for(r=1; r<=n; r++)
    {
      for(c=1; c<=m; c++)
        {
           if(c<=n+1-r||c>=n-1+r)
{
printf("*");
} else printf(" "); } printf("\n"); printf("\t"); } return 0; }

[/et_pb_text][et_pb_button button_text=”practice online” _builder_version=”4.4.6″ button_url=”https://digitalmind.online/practice-your-c-prograam/” url_new_window=”on” button_alignment=”right” hover_enabled=”0″][/et_pb_button][et_pb_text _builder_version=”4.4.2″]

2. Merge two inverted triangle pattern: while Loop

 

[/et_pb_text][et_pb_text _builder_version=”4.2.2″ text_font=”|600|||||||” text_text_color=”#000000″ border_radii=”on|8px|8px|8px|8px” border_width_all=”3px” border_style_all=”double”]

int main()
{
    int r,c,n,m;
    printf("\n\tEnter no:");
    scanf("%d",&n);
    printf("\n\tEnter no:");
    scanf("%d",&m);
    printf("\t");
    r=1;
    while(r<=n)
    {
       c=1;
       while(c<=m)
       {
if(c<=n+1-r||c>=n-1+r)
{ printf("*"); } else { printf(" "); } c++; } r++; printf("\n"); printf("\t"); } }

[/et_pb_text][et_pb_image src=”https://digitalmind.online/wp-content/uploads/2020/04/inverted_triangle.png” _builder_version=”4.4.2″][/et_pb_image][et_pb_button button_text=”practice online” _builder_version=”4.4.6″ button_url=”https://digitalmind.online/practice-your-c-prograam/” url_new_window=”on” button_alignment=”right” hover_enabled=”0″][/et_pb_button][et_pb_text _builder_version=”4.4.2″]

3. Merge two inverted triangle pattern: do..while Loop

 

[/et_pb_text][et_pb_text _builder_version=”4.2.2″ text_font=”|600|||||||” text_text_color=”#000000″ border_radii=”on|8px|8px|8px|8px” border_width_all=”3px” border_style_all=”double”]

int main()
{
    int r,c,n,m;
    printf("\n\tEnter no:");
    scanf("%d",&n);
     printf("\n\tEnter no:");
    scanf("%d",&m);
    printf("\t");
    r=1;
    do
    {
      c=1;
      do
      {
if(c<=n+1-r||c>=n-1+r) { printf("*"); } else { printf(" "); } c++; }while(c<=m); r++; printf("\n"); printf("\t"); } while(r<=n); }

[/et_pb_text][et_pb_image src=”https://digitalmind.online/wp-content/uploads/2020/04/inverted_triangle.png” _builder_version=”4.4.2″][/et_pb_image][et_pb_button button_text=”practice online” _builder_version=”4.4.6″ button_url=”https://digitalmind.online/practice-your-c-prograam/” url_new_window=”on” button_alignment=”right” hover_enabled=”0″][/et_pb_button][et_pb_text _builder_version=”4.2.2″ text_font=”Verdana||||||||” text_text_color=”#000000″ custom_margin=”||1px|||”]

Recommended posts are following 

C Programming code – Right angle Triangle pattern using star symbol using For, while and do..while loop.

C programming code- Inverted right triangle pattern using star symbol and using For, while and do.. while loop  

C programming code- Mirror right triangle pattern using star symbol and using For, while, do..while loop.

C program- Inverted Mirror right angle triangle using the star symbol and using For, while and do..while Loop

C program- How to make “X” type pattern using the symbol in C programming using For, while and do while loop

 

[/et_pb_text][et_pb_text _builder_version=”4.2.2″]

Follow me on Facebook

[/et_pb_text][/et_pb_column][/et_pb_row][/et_pb_section]