programming in c – recursive function to print star pattern 2

currently_:
_feeling: tired
_listening: high and mighty color – ichirin no hana // [gou on progressive]
_watching: naruto shippuden [153] season 7 episode 12 – following the masters shadow
_reading: help with pl/sql

-

the second star pattern is as follows:
*****
 ****
  ***
   **
    *

as with the previous program, this one also asks for user input as to how many lines are needed.

code:
#include <stdio.h>
#include <conio.h>
int space, count, line = 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; i > 0; i--)
printf("*");
x--;
printf("\n");
space = 0;
while(space <= line)
{
printf(" ");
space++;
}
if(line < count)
line++;
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.