C Online Compiler
Example: Print Star Pattern without using loop in C
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// Print Star Pattern without using loop in C #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; }
10
Output
Clear
ADVERTISEMENTS