how to add space to the following star pattern?

How is it possible to print the following pattern?

    *
   **
  ***
 ****
*****
****
***
**
*

How can we add the spaces during the first half of the pattern? I only managed to get the second half of the pattern right:

#include <iostream>

using namespace std;

void printpattern(int n)
{
    for (int r = 0; r <= n; r++)
    {
        for (int z = 0; z <= r; z++) {
            cout << "*";
        }

        cout << endl;
    }
}

int main()
{
    int n = 5;
    printpattern(n);
}

Although comments suggest using std::string, I believe this was intended to be written using only loops. This works:

void printpattern(int n)
{
  // print first half.
  for (int i = 0; i < n; ++i) {
    // print spaces
    for (int r = n - i; r > 0; --r)
      std::cout << ' ';

    // print stars.
    for (int j = i; j > 0; --j) 
      std::cout << '*';

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

  /// print second half. No need to print spaces here.
  for (int i = 1; i <= n; ++i) {
    for (int r = n - i; r >= 0; --r) 
      std::cout << '*';

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

Top 30 Patterns in Java: How to Print Star, Number and Character, I have classified the programs under the following clusters : Star Patterns in Java; Numeric Patterns; Character Patterns. Let's get started. :-)  This article precisely focuses on pattern programs in Java. I have classified the programs under the following clusters : Pattern Programs in Java. Star Patterns in Java; Numeric Patterns; Character Patterns; Let’s get started. :-) Star Patterns in Java. First, let us begin with the basic and the commonly asked pattern program in Java i.e


If one is afraid of using loops such thingies can of course always be solved with recursion and a little math:

#include <iostream>

void pattern(int n, int p = 0)
{   
    if (!n) return;
    if (!p) { pattern(2 * n * n - n, n); return; }
    int k = --n / p, o = n % p + 1, t = o - (p - k);
    std::cout.put(" *"[k >= p && t < p || k < p && t >= 0]);
    --o || std::cout.put('\n');
    pattern(n, p);
}

Automatic Control in Aerospace 1989: Selected Papers from the IFAC , This brings the memory space for the guide star pairs and the MAT matrices to 579,480 For example, an increase of the spatial error from 8 to 40 arcsec would result in CONCLUSIONS Using the general star pattern recognition algorithm  C++ program to convert temperature. C++ program to encrypt and decrypt the string. C++ program to find area of the circle. C++ program to display Fibonacci series using loop and recursion. C++ program to print star pyramid patterns. C++ Hello World Program. C++ program to print Pascal’s and Floyd’s triangle.


It's easier to do this by composing a longer string and using a sliding view.

That's pretty straightforward in C++:

#include <iostream>
#include <string>
#include <string_view>

void printpattern(std::size_t n)
{
    const auto s = std::string(n, ' ') + std::string(n, '*') + std::string(n, ' ');
    for (std::size_t i = 1;  i < n*2;  ++i)
        std::cout << std::string_view(s.data()+i, n) << '\n';
}

int main()
{
    printpattern(5);
}

You could of course make the space padding be of length n-1 on both sides, and use a more conventional loop starting i at zero:

    const auto s = std::string(n - 1, ' ') + std::string(n, '*')
                 + std::string(n-1, ' ');
    for (std::size_t i = 0;  i < n * 2 - 1;  ++i)

It's up to you whether saving two characters of temporary string is worthwhile.

Python Pattern Programs, To print Star Pattern in A shape in python you have to use two for loops. the first loop is Duration: 11:19 Posted: May 4, 2017 Star patterns is a series of * used to create some pattern or any geometrical shape. In this exercise I have compiled a list of Star patterns to practice. Learn C programming, Data Structures tutorials, exercises, examples, programs, hacks, tips and tricks online.


triangle star pattern with spaces using C++ Urdu Hindi, tringle star pattern using C++ HINDI|URDU By Rao Israr. Please subscribe, comment, share and Duration: 7:39 Posted: Dec 26, 2017 All Pyramid and Pattern Printing programs based on problems popularity and frequently asked in Interview, these programs has explanation and Output. Pyramid, Star Series and Patterns Programs in C language. Half, Full, Incremented and Decrement Stars Series, Pyramid Pattern programs. Program - 1 


The Artist's Guide to GIMP, 2nd Edition: Creative Techniques for , The first is to create some voids in space, places with a lack of stars. Avoid any obvious patterns in the voids and remove any patterns created when the  Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. Learn more How to print star pattern in JavaScript in a very simple manner?


30 Pattern Programs in Java: Star, Number & Character Patterns , Swing In Java : Know How To Create GUI With Examples · Java AWT Tutorial – One Stop Solution for Beginners · Java Applet Tutorial Top 30 Patterns in Java: How to Print Star, Number and Character I have classified the programs under the following clusters : System.out.print( " " ); // printing space. To print patterns in C++ programming, you have to use two for loop, the outer for loop and the inner for loop. The outer for loop is responsible for rows and the inner for loop is responsible for columns.