How to print a star pattern without using loop in the c programming language
ADVERTISEMENTS
How to print a star pattern without using a 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 <stdio.h>
#include <math.h>
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) ? printf("*") : printf(" ");
if ((i - (2 * n - 1) * (r - 1)) % (2 * n - 1) == 0) {
printf("\n");
r++;
}
if (i++ < n * (2 * n - 1))
starPattern(n);
}
int main() {
// size of the pattern
int x;
printf("-----Enter the size of the pattern-----\n");
scanf("%d", &x);
// This will print the pattern
starPattern(x);
return 0;
}
Output:
-----Enter the size of the pattern-----
10
*
***
*****
*******
*********
***********
*************
***************
*****************
*******************