Author Topic: Number pattern of example #3 - double spacing  (Read 892 times)

administrator

  • Administrator
  • Full Member
  • *****
  • Posts: 69
Number pattern of example #3 - double spacing
« on: October 26, 2011, 10:44:26 am »
Enter a number: 7

7 7
6 6

int main()
{
   int n = 0;
   printf("Enter a number: ");
   scanf("%d", &n);
   int spacecount = n + 1;
   for(int i = n; i >= 0; i--)
   {
      int count = spacecount - i + 1;
      if( (spacecount%2) == 1)
      {
         if((i % 2) == 1)
            count--;
      }
      else
      {
         if((i % 2) == 0)
            count--;
      }
      for(int j = 0; j < count; j++)
         std::cout << i << " ";
      std::cout << "\n";
   }

   for(int i = 1; i <= n; i++)
   {
      int count = spacecount - i + 1;
      if( (spacecount%2) == 1)
      {
         if((i % 2) == 1)
            count--;
      }
      else
      {
         if((i % 2) == 0)
            count--;
      }

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

   return 0;
}
5 5 5 5
4 4 4 4
3 3 3 3 3 3
2 2 2 2 2 2
1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1
2 2 2 2 2 2
3 3 3 3 3 3
4 4 4 4
5 5 5 5
6 6
7 7


Source Code:

« Last Edit: October 29, 2011, 12:16:23 pm by admin softwareandfinance »

 


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