/**//* Draw a hollow diamond based on the character and width entered by the user */
#include < stdio.h >
#include < stdlib.h >
void Main ()
... {
int i,j,k,num;
Char ch;
System ("CLS");//Clear screen
printf ("Please enter a number:");
scanf ("%d", &num);//Prompt user for input width
printf ("Please enter a char:");
Fflush (stdin);//Clear buffer
scanf ("%c", &ch);//Prompts the user to enter the characters to be printed
for (i=1;i<=num;i++)//loop print upper part
... {
for (j=num-i;j>=0;j--)
... {
Putchar (");
}
for (j=1;j<=2*i-1;j++)//To print out the top half of the diamond using knockout method on line 1th and last 1 lines
... {
if (j==1| | J==2*I-1)
... {
printf ("%c", ch);
}
Else
... {
Putchar (");
}
}
Putchar (");
}
for (i=num-1;i>=1;i--)//print out the bottom half of the diamond
... {
for (j=0;j<=num-i;j++)
... {
Putchar (");
}
for (j=1;j<=2*i-1;j++)//The bottom half of the diamond is printed out by the knockout method on line 1th and the last 1 lines as judged
... {
if (j==1| | J==2*I-1)
... {
printf ("%c", ch);
}
Else
... {
Putchar (");
}
}
Putchar (");
}
Getch ();
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.