Author Topic: Number pattern to display triangle with base on top  (Read 924 times)

administrator

  • Administrator
  • Full Member
  • *****
  • Posts: 69
Number pattern to display triangle with base on top
« on: October 26, 2011, 03:04:52 pm »
Here is the C++ program to display numbers that forms the pattern of triangle with base on top.

Code:
//Source Code Listing

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

   int count = n;
   for (i = 1; i <= n; i++)
   {
      for(int k = 0; k < i; k++)
         std::cout << " ";
      for(int j = 0; j < count; j++)
      {
         std::cout << i;
         std::cout << " ";
      }
      std::cout << "\n";
      count--;
   }

   std::cout << "\n\n";

}
« Last Edit: November 01, 2011, 05:45:12 pm by kathir »

dollor

  • Newbie
  • *
  • Posts: 8
Re: Number pattern to display triangle with base on top
« Reply #1 on: October 28, 2011, 03:51:35 am »
Thank you 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