Program to make stars mostly done, need help?
Ok, I am new to this board so if I have gone out of line or done something by accident, I will apologize in advance. I want to make a program that generates a number of lines with stars. Only Odd numbers though. The user is asked to input a number and the output places that many lines in out of stars. EX>.
Input number: 5;
*
***
*****
***
*
It doesn't put the line 2 with 2 stars and line 4 with 4 stars. Number being inputted is number of stars on middle line. Eg. 7 would have 7 stars.
So far this is what I have...
Code:
#include <stdio.h>
int main (void)
{
int num, space, spaces, line;
printf("Please enter an Odd number of lines in the diagram: ");
scanf("%d", &num);
if((num <= 0)||(num%2 == 0))
printf("\nPlease input a positive Odd Integer");
else{
space = num;
for (int i=1; i<=num-2; i++)
{
for (int j=1; j<=space; j++)
printf(" ");
for (int j=1; j<=2*i-1; j++)
printf("*");
printf("\n");
space--;
}
}
return 0;
}
Thank you in advance for reading this post.