c program print diamond pattern using recursion -- frndslink

c program print diamond using recursion

c program print diamond using recursion, in previous post we see how create

program print diamond pattern with simple C program.

 

Now we see how print diamond pattern using recursion.

<h2>c program print diamond using recursion</h2>


#include <stdio.h>
#include<conio.h>

void print (int);

int main () {
int rows;

scanf("%d", &rows);

print(rows);

return 0;
}

void print (int s) {
int f, n;
static int stars = -1;

if (s <= 0)
return;

n = s - 1;
stars += 2;

for (f = 0; f < n; f++)
printf(" ");

for (f = 0; f < stars; f++)
printf("*");

printf("\n");

print(--s);

n = s + 1;
stars -= 2;

for (f = 0; f < n; f++)
printf(" ");

for (f = 0; f < stars; f++)
printf("*");

printf("\n");
getch();
}

output:

c program print diamond pattern using recursion -- frndslink
fig 1

press enter it will appear full diamond line by line like fig 2

c program print diamond pattern using recursion -- frndslink
fig 2

have a nice coding 🙂

READ  c program to reverse a number

Leave A Comment

Your email address will not be published. Required fields are marked *