/* Print a Triangle of Stars on it's tip
Input: a positive integer
Output: an n-sized triangle */
void Triangle(int s)
{
int i = 0;
while (s > 0)
{
for (i = 0; i < s; i++)
{
printf("*");
}
printf("\n");
s = s - 1;
}
}
/* Print a Triangle of Stars on it's base
Input: a positive integer
Output: an n-sized triangle */
void TriangleTwo(int t)
{
int i = 0;
int x = 0;
int y = 1;
int counter = 0;
while (counter < t)
{
x = t - (t - y);
for (i = 0; i < x; i++)
{
printf("*");
}
printf("\n");
y++;
counter++;
}
}
**************
void TriangleTwo(int t)
{
if (t < 1)
return; /* base case */
else
{
TriangleTwo(t - 1); /* recursive step */
while(t > 0)
{
printf("*");
t--;
}
printf("\n");
}
}
*****************
void printIt(int row, int star)
{
if(row)
{
putchar('*');
--star;
if(star == 0)
{
putchar('\n');
star = row - 1;
--row;
}
printIt(row, star);
--row;
}
else
{
return;
}
}
**********************
// Print n asterisks and a newline
void asterisks(int n)
{
if (n <= 0)
putchar('\n');
else
{
putchar('*');
asterisks(n - 1);
}
}
// Descending triangle (large at top, small at bottom)
void t1(int n)
{
if (n > 0)
{
asterisks(n);
t1(n - 1);
}
}
// Ascending triangle (small at top, large at bottom)
void t2(int n)
{
if (n > 0)
{
t2(n - 1);
asterisks(n);
}
}
**********************
/* Print a Triangle of Stars on it's tip
Input: a positive integer
Output: an n-sized triangle */
void Triangle(int s)
{
if (s == 1)
printf("*"); /* base case */
else
{
for(int i = 1; i <= s; i++)
{
printf("*");
}
printf("\n");
Triangle(s - 1); /* recursive step */
}
}
/* Print a Triangle of Stars on it's base
Input: a positive integer
Output: an n-sized triangle */
void TriangleTwo(int t)
{
if (t < 1)
return; /* base case */
else
{
TriangleTwo(t - 1); /* recursive step */
while(t > 0)
{
printf("*");
t--;
}
printf("\n");
}
}
Input: a positive integer
Output: an n-sized triangle */
void Triangle(int s)
{
int i = 0;
while (s > 0)
{
for (i = 0; i < s; i++)
{
printf("*");
}
printf("\n");
s = s - 1;
}
}
/* Print a Triangle of Stars on it's base
Input: a positive integer
Output: an n-sized triangle */
void TriangleTwo(int t)
{
int i = 0;
int x = 0;
int y = 1;
int counter = 0;
while (counter < t)
{
x = t - (t - y);
for (i = 0; i < x; i++)
{
printf("*");
}
printf("\n");
y++;
counter++;
}
}
**************
void TriangleTwo(int t)
{
if (t < 1)
return; /* base case */
else
{
TriangleTwo(t - 1); /* recursive step */
while(t > 0)
{
printf("*");
t--;
}
printf("\n");
}
}
*****************
void printIt(int row, int star)
{
if(row)
{
putchar('*');
--star;
if(star == 0)
{
putchar('\n');
star = row - 1;
--row;
}
printIt(row, star);
--row;
}
else
{
return;
}
}
**********************
// Print n asterisks and a newline
void asterisks(int n)
{
if (n <= 0)
putchar('\n');
else
{
putchar('*');
asterisks(n - 1);
}
}
// Descending triangle (large at top, small at bottom)
void t1(int n)
{
if (n > 0)
{
asterisks(n);
t1(n - 1);
}
}
// Ascending triangle (small at top, large at bottom)
void t2(int n)
{
if (n > 0)
{
t2(n - 1);
asterisks(n);
}
}
**********************
/* Print a Triangle of Stars on it's tip
Input: a positive integer
Output: an n-sized triangle */
void Triangle(int s)
{
if (s == 1)
printf("*"); /* base case */
else
{
for(int i = 1; i <= s; i++)
{
printf("*");
}
printf("\n");
Triangle(s - 1); /* recursive step */
}
}
/* Print a Triangle of Stars on it's base
Input: a positive integer
Output: an n-sized triangle */
void TriangleTwo(int t)
{
if (t < 1)
return; /* base case */
else
{
TriangleTwo(t - 1); /* recursive step */
while(t > 0)
{
printf("*");
t--;
}
printf("\n");
}
}
Hi Sir,
ReplyDeleteI have stuff to found the solution of triangle in c.
The out put will be in the form of:
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
Please reply soon........