The So-Called Christmas Tree
The last triangle looks different from the previous ones in that it's actually standing like a normal triangle should!
The user inputs the base (which has to be an odd integer) of the triangle.
For instance:
Base is 9
*
***
*****
*******
*********
I have a rough draft in source code.
Code:
#include <stdio.h>
#include <conio.h>
#include <string.h>
int GetCountOfStarsInLine(int line);
void PrintNSpaces(int line);
void PrintStars(int line);
main()
{
int line, height;
for (line=1; line<=height; line++)
{
PrintNSpaces(GetCountOfStarsInLine(line));
PrintStars(GetCountOfStarsInLine(line));
}
getch();
}
void PrintStars(int line)
{
int n;
PrintNChars(n, "*");
}
void PrintNChars(int n, char *string)
{
int i;
for(i=0; i<n; i++)
{
printf(string);
}
}
int GetCountOfStarsInLine(int line)
{
int stars;
stars=2*line-1;
return 2*line-1;
}
Any ideas? How about fixing the last function there? If there are other areas that need to be adjusted, please let me know