w3codeworld logo
  • Home
  • C
  • C++
  • Java
  • Python3
  • JavaScript
  • C#
  • PHP
  • Codeigniter
  • Laravel
  • Articles
  1. Home
  2. Articles
  3. How to print a star pattern without using loop in the c++ programming language
  • PHP
  • Codeigniter
  • Laravel
  • C
  • C++
  • Java
  • Python3
  • JavaScript
  • C#

How to print a star pattern without using loop in the c++ programming language

  • Author: Admin
  • Last Updated: 2020-12-26
  • Category: C++

How to print a star pattern without using loop in the c++ programming language. In this program, you will learn how to print the star pattern without using the loop.

 

Take an example to print this star pattern through a c++ program:

// How to print a star pattern without
// using loop in the c++ programming language
#include <bits/stdc++.h>
#include <cmath>
using namespace std;

int i = 1, r = 1;

// It's the recursive function
// to print the star pattern
void starPattern(int n)
{
    ((int) sqrt(pow((i - (2 * n - 1) *(r - 1) - n), 2)) < r) ? cout << "*" : cout << " ";

    if ((i - (2 * n - 1) * (r - 1)) % (2 * n - 1) == 0)
    {
        cout << "\n";
        r++;
    }

    if (i++ < n * (2 * n - 1))
        starPattern(n);
}

int main()
{
    // size of the pattern
    int x;

    cout << "-----Enter the size of the pattern-----\n";
    cin >> x;

    // This will print the pattern
    starPattern(x);
    return 0;
}

 

Output:

-----Enter the size of the pattern-----
12
           *           
          ***          
         *****         
        *******        
       *********       
      ***********      
     *************     
    ***************    
   *****************   
  *******************  
 ********************* 
***********************

 

Tags:

# print star pattern without using loop in c++

# write a program to print done without using any loop in c++

# print all numbers between 1 to n without using any loop in c++

 

Related Articles

Write a c++ program to store information of a student using the structure with the for loop How to write a c++ program to find the sum of natural numbers using recursion Write a c++ program to rotate the matrix by k times in a clockwise direction using the function Write a c++ program to print a hollow square star pattern with diagonal using loops (for and while loop) How to rearrange positive and negative numbers in array in c++ language How to print a star pattern without using loop in the c++ programming language C++ program to find the number occurring the odd number of times in an array Write a program of spiral pattern printing in c++ language Write a c++ program to convert an array into zig-zag fashion using the function Write a c++ program to find the sum of a zig-zag pattern in a given matrix using the recursion How to find the sum of each row and column of a matrix in c++ language Write a program to find the transpose of a matrix in c++ language Write a program to make transformation matrix rotation 90 degrees clockwise in c++ language How to print the hollow diamond pattern in c++ language Write a program to find quotient and remainder in c++ language Write a program to draw the half pyramid pattern in c++ language of stars using the for loop How to print the rhombus pattern in the c++ language of the stars using the for loop Write a program to print the left & right arrow pattern in c++ language Write a c++ program to draw a rectangle using for loop Write a program to print the pascal triangle pattern in c++ language Write a program to print Floyd's triangle number pattern in c++ language Write a program to print the matrix pattern in c++ language using the for loop C++ program to print diamond pattern of stars by using the for loop Write a c++ program to print the butterfly pattern of the numbers by using the for loop How to check whether a number is an integer or float in c++ language by using the while loop Write a c++ program to find factors of a number using while loop & for loop How to swap the two integers or real numbers without using the third variable in the c++ language Write a c++ program to convert the reverse case of an input character Write a c++ program to check whether a character is an alphabet or not by using the if-else statement and using the conditional operator Write a c++ program to check the input integer number is an Armstrong number using the for loops & while loops C++ program to check leap year using the if-else and by using the switch case statement C++ program to find the roots of a quadratic equation using the sqrt() function with the if-else condition C++ program to find GCD of two numbers using the while loop and using the for loop C++ program to find LCM of two numbers using for loop and with GCD calculation C++ program to calculate the power of N number using for loop and by using pow function C++ program to find the Normal & Trace of a square matrix by using the for loop C++ program to multiply two same dimension matrices by using the for loop C++ program to find the SUM of the N input numbers using arrays with for loop C++ program to find the largest and smallest element in an array by using for loop C++ program to print the multiplication table of any integer number with multiplication range C++ program to print prime numbers from 1 to N using for loop C++ program to check input number is even or odd using if-else statement and with conditional operator C++ program to find the average of N numbers by using for loop C++ program to reverse a string by using the while & for loop C++ program to find sum of digits of a number using while loop of any integer number C++ program to check palindrome number using while loop or not using function of any number C++ program to generate the fibonacci series using iteration C++ program to find factorial of a number using for loop C++ program to check the input character is a vowel or consonant character C++ program of decision making by using the switch case statement
Recent Articles
  • Write a program to find all the patterns of 0(1+)0 in the given string
  • C# program to enter two numbers and find their sum
  • Write a c++ program to store information of a student using the structure with the for loop
  • Write a c program to store information of a student using the structure with the for loop
  • How to write a c++ program to find the sum of natural numbers using recursion
  • How to write a c program to find the sum of natural numbers using recursion
  • Write a python program to convert an array into zig-zag fashion using the function
  • C program to perform input/output of all basic data types
  • Write a python program to print a hollow square star pattern with diagonal using loops (for and while loop)
  • Write a c program to make a circular rotation of an array by k positions using the loops
View All Articles
  W3Codeworld

Get the latest updates

  • ABOUT US
  • About Company
  • Contact Us
  • Terms Conditions
  • Privacy Policy
  • Top Tutorials
  • PHP
  • Codeigniter
  • Laravel
  • Top Articles
  • C
  • C++
  • Java
  • Python
  • JavaScript
  • PHP

© Copyright 2020-2021. All Rights Reserved.