This program will print a shape on the screen using asterisks (“*”) characters.

The user will be prompted to enter an ODD number between 1 and 99 (you may assume test cases will not be beyond this range and that all test cases will be odd numbers). The shape that will be printed resembles a diamond, where the number provided by the user represents the number of *’s printed on the middle line. The line above and below will be centered and will have 2 less *’s than the middle line. This reduction by 2 *’s for each line continues until a line with a single * is printed at the top and bottom of the figure.

// output
Example 1:
Enter an odd number (1-100): 1
*
Example 2:
Enter an odd number (1-100): 5
*
***
*****
***
*

#include <stdio.h>
int main ()
{
printf ("Enter an odd number (1-100): ");
int oddNumber;
scanf ("%d", &oddNumber);
int length = oddNumber / 2;
for ( int i = 0; i <= length; i++ ) {
for ( int j = length - i - 1; j >= 0; j-- )
printf (" ");
for ( int k = 1; k < 2 * (i + 1); k++ )
printf ("*");
printf ("\n");
}
for ( int i = 0; i < length; i++ ) {
for ( int j = 1; j <= i + 1; j++ )
printf (" ");
oddNumber -= 2;
for ( int k = oddNumber; k >= 1; k-- )
printf ("*");
printf ("\n");
}
return 0;
}

### Like this:

Like Loading...

*Related*

## Published by Shahab

Completed B.Sc in CSE, @United International University, Dhaka.
Currently working as Development Engineer, Android and iOS Application.
View all posts by Shahab

Solved in Python 3.1.2:

x = int(input(“Thickest point of diamond? (positive odd integer)”))

for y in range(1, x, 2):

print((“*” * y).center(80))

for y in range(x, -1, -2):

print((“*” * y).center(80))

Shahab, your own solution is run. try to run it and see for yourself. this problem is too complicated.

I meant that your own solution is wrong

I have finally solved this problem.