- #1
bella mason
- 4
- 0
a recursion to arrange a stars ! it's difficult :(
hello ! :) my name is bella and i am still a student. I've instructed by my lecturer to create a simple program that will appear such as this output :
Enter number of star : 5(user will key in the data)
*
**
***
****
***** (result)
****
***
**
*
My question is I only can make the last five * to be appear and my coding is just like this.
#include <stdio.h>
#include <conio.h>
void recursion(int);
void recursion1(int);
int main()
{
int n;
printf("\nEnter number of star : ");
scanf("%d",&n);
printf("\n");
recursion(n);
recursion1(n);
printf("\n");
getch();
}
void recursion(int n)
{
int i;
if (n==1)
{
printf("*");
printf("\n");
}
else
{
for (i=0; i>n; i--)
printf("*");
printf("\n");
recursion(n-1);
}
}
void recursion1(int n)
{
int i;
if (n==1)
{
printf("*");
printf("\n");
}
else
{
for (i=0; i<n; i++)
printf("*");
printf("\n");
recursion1(n-1);
}
}
My lecture said the coding will have two calling function but what should I change from my first calling function ? I haven't sleep for a couple of days thinking about it and yet, I still didn't find it's answer. Could it be other way of coding to appear the same result ? Can someone help me and guide me ? :((
notes : it's only C languange. ;) TQ
hello ! :) my name is bella and i am still a student. I've instructed by my lecturer to create a simple program that will appear such as this output :
Enter number of star : 5(user will key in the data)
*
**
***
****
***** (result)
****
***
**
*
My question is I only can make the last five * to be appear and my coding is just like this.
#include <stdio.h>
#include <conio.h>
void recursion(int);
void recursion1(int);
int main()
{
int n;
printf("\nEnter number of star : ");
scanf("%d",&n);
printf("\n");
recursion(n);
recursion1(n);
printf("\n");
getch();
}
void recursion(int n)
{
int i;
if (n==1)
{
printf("*");
printf("\n");
}
else
{
for (i=0; i>n; i--)
printf("*");
printf("\n");
recursion(n-1);
}
}
void recursion1(int n)
{
int i;
if (n==1)
{
printf("*");
printf("\n");
}
else
{
for (i=0; i<n; i++)
printf("*");
printf("\n");
recursion1(n-1);
}
}
My lecture said the coding will have two calling function but what should I change from my first calling function ? I haven't sleep for a couple of days thinking about it and yet, I still didn't find it's answer. Could it be other way of coding to appear the same result ? Can someone help me and guide me ? :((
notes : it's only C languange. ;) TQ