Author Topic: V shape pattern with numbers using for loops  (Read 2754 times)

administrator

  • Administrator
  • Full Member
  • *****
  • Posts: 69
V shape pattern with numbers using for loops
« on: October 26, 2011, 02:51:05 pm »
Here is the number pattern example using loops for V shape.

Code:
//Source Code Listing


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

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

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

      count++;

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

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

	return 0;
}

« Last Edit: November 16, 2011, 04:48:04 pm by kathir »

 


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