#include void Print(char c, int n); // print c, n times void Print(char c, int n) { int i; for (i=0; i < n; i++) printf("%c", c); } // draw a diamond of a given diameter (odd positive integer n) void DrawDiamond(int n); void DrawDiamond(int n) { int line, space, star; // check parameter n to be positive integer and odd! if (n < 1 || (n%2==0)) return; // draw diamond: divide and conquer // step1: draw top triangle space = n/2; // go all the way to 0, space-- star = 1; // go all the way to n, star+=2 for(line = 0; line < (n+1)/2; line++) { Print(' ', space); Print('*', star); space--; star+=2; Print('\n', 1); } // step2: draw bottom upside down triangle space = 1; // space++ star = n-2; // star-=2 for(line = 0; line < n/2; line++) { Print(' ', space); Print('*', star); space++; star-=2; Print('\n', 1); } } int main() { DrawDiamond(5); DrawDiamond(7); DrawDiamond(9); DrawDiamond(11); return 0; }