programming in c – recursive function to print star pattern 1

currently_:
_feeling: sleepy
_listening: delays – this towns religion // [you see colours]
_watching: naruto shippuden [152] season 7 episode 11 – somber news
_reading: help with pl/sql

-

this program uses a recursive function to print the star pattern shown below.
*******
 *****
  ***
   *

the number of lines are to be inputted by the user.

code:
#include <stdio.h>
#include <conio.h>
int j, count, t = 0;
void star(int);
int main()
{
int x;
system("cls");
printf("enter the number of lines: ");
scanf("%d", &x);
count = x;
star(x);
getch();
}
void star(int x)
{
int i;
for(i = x + x - 1; i > 0; i--)
printf("*");
x--;
printf("\n");
j = 0;
while(j <= t)
{
printf(" ");
j++;
}
if(t < count)
t++;
if(x > 0)
star(x);
}

_lolex.

Advertisement
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.