OCJP

C Patterns Programs with Multiple Loops (Complex)

In our earlier discussion, C Patterns we have demonstrated Pattern, Pyramid Programs using For Loop in C Language . Now we are going to demonstrate more complex program for Pattern.

#include<stdio.h>
#include<conio.h>
void main()
{
	int i,j;
	clrscr();

	for(i=1;i<=5;i++) //for 5 Rows
	{
		//Loop for Increasing Space
		for(j=1;j<=i;j++)
		{
		printf("  "); //two space
		}
		//loop to print half triangle
		for(j=i;j<=5;j++)  //ends to 5, start with dynamic
		{
		printf("%d ",j); //One Space and J
		}

		//for another triangle
		for(j=4;j>=i;j--) //starts from 4 to i (Ends Dynamic)
		{
		printf("%d ",j);
		}

	printf("\n");
	}

	getch();
}
/*
1 2 3 4 5 4 3 2 1
  2 3 4 5 4 3 2
    3 4 5 4 3 2
      4 5 4
	5
*/
Complex Pattern Pyramid in C Programming
#include<stdio.h>
#include<conio.h>
void main()
{
	int i,j;
	clrscr();

	for(i=5;i>=1;i--) //for 5 Rows But Decreasing
	{
		//Loop for Increasing Space
		for(j=1;j<=i;j++)
		{
		printf("  "); //two space
		}
		//loop to print half triangle
		for(j=1;j<=(6-i);j++)  //ends to Dynamic, start with 1
		{
		printf("%d ",j); //One Space and J
		}

		//for another triangle
		for(j=(5-i);j>=1;j--) //starts With Dynamic to 1
		{
		printf("%d ",j);
		}

	printf("\n");
	}

	getch();
}
/*
1 2 3 4 5 4 3 2 1
  1 2 3 4 3 2 1
    1 2 3 2 1
      1 2 1
	1
*/

Complex Pattern Pyramid in C Programming 1 to 1

Leave a Reply

Your email address will not be published. Required fields are marked *


× How can I help you?