Hi
I need to write a program that will print a diamond shape using astericks, i can only use printf for one character so i will have to use loops. The user needs to be able to input the amount of rows they would like. and then the program print the diamond with that amount of rows.
I made this program below to just print a diamond with 9 rows for another piece of work. Is there any way i can just alter it so that i can input the amount of rows without having to change the code to much?
any help very much appreciated thankyou,
Code:
#include <stdio.h>
int main ()
{
int line, space, asterisk;
for (line = 1; line <= 9; line += 2) /* Top half */
{
for (space = (9 - line) /2; space > 0; space--)
printf (" ");
for (asterisk = 1; asterisk <= line; asterisk++)
printf("*");
printf ("\n");
}
for (line = 7; line >= 0; line -= 2) /*Bottom half */
{
for (space = (9 - line) /2; space > 0; space--)
printf (" ");
for (asterisk = 1; asterisk <= line; asterisk++)
printf("*");
printf ("\n");
}
getch(0);
return(0);
}