UncleCoder.com

UncleCoder.com

Free programming examples and instructions

C program to generate a pattern

C program to generate pattern

by Krishna viswambharan


Posted on 01 Sep 2017 Category: C Views: 262

Edited on 05 Sep 2017


C program to generate  a pattern

C program to generate a triangular pattern

Here is a sample C program to generate the following pattern

1

1 2

1 2 3

1 2 3 4

1 2 3 4 5

1 2 3 4

1 2 3

1 2

1

C code for the above is given as follows:-

#include<stdio.h>
#include<conio.h>
void main()
{
   int i,j;
   for(i=1;i<=5;i++)
   {
      for(j=1;j<=i;j++)
      {
         printf(“%d”,j);
      }
      printf(“\n”);
   }
   for(i=1;i<=5;i++)
   {
	  for(j=1;j<=5-i;j++)
	  {
		printf(“%d”,j);
	  }
	  printf(“\n”);
   }
   getch();
}

output



Leave a Comment:


Advertisement