+ 1
Stars triangle in C
Hello,I've a question about printing stars triangle(specifically isosceles triangle). What is the flowchart of the algorithm of solving this problem? I meant something like: 3: -*- *** 5: --*-- -***- *****
1 Resposta
0
I was never any good with flowcharts, and pretty bad with algorithm, but if I were to anyways, this is how I'd be writing it, hope you get the idea from it : )
// Isosceles triangle
#include <stdio.h>
int main()
{
int n, mid;
scanf("%d", &n);
if(n < 3) n = 3;
mid = n / 2;
for(int count = 1; count <= n; count += 2)
{
for(int col = 0; col < n; col++)
{
if(col < mid || col >= mid + count)
printf("%c", '-');
else
printf("%c", '*');
}
mid--;
printf("\n");
}
return 0;
}