Author Topic: Number pattern to display triangle with base on left  (Read 1264 times)

administrator

  • Administrator
  • Full Member
  • *****
  • Posts: 69
Number pattern to display triangle with base on left
« on: October 26, 2011, 03:14:15 pm »
Here is C program to display number pattern of triangle with base on left

Code:
//Source Code Listing

void main()
{
   int i, j, k, n = 0;
   printf("Enter a number: ");
   scanf("%d", &n);
   printf("\n\n");

   for (i = 1; i <= n; i++)
   {
      for (k = 1; k <= i; k++)
         printf("%d ", i);
      for (j = 0; j < (n - i)* 2; j++)
         printf(" ");
      for (j = 1; j <= i; j++)
         printf(" ");
      printf("\n");
   }

   for (i = n - 1; i >= 1; i--)
   {
      for (k = 1; k <= i; k++)
         printf("%d ", i);
      for (j = 0; j < (n - i)* 2; j++)
         printf(" ");
      for (j = 1; j <= i; j++)
         printf(" ");
      printf("\n");
   }
   printf("\n\n");
}
« Last Edit: November 16, 2011, 04:47:25 pm by kathir »

dollor

  • Newbie
  • *
  • Posts: 8
Re: Number pattern to display triangle with base on left
« Reply #1 on: October 28, 2011, 03:49:28 am »
Thank u sir!!

 


Disclaimer: This web site is for educational and informational purposes only. Click here to read the Disclaimer.
Content copyright 2010-2014. Kathiresan. All rights reserved.
This page is using SMF version 2.0.1