Print a diamond code of a specified size under a C + + command prompt form

Source: Internet
Author: User

Print a diamond code of a specified size under a C + + command prompt form

Under VS2010, create a new empty project. Add the source file and paste the code in it.

The size of the diamond can be controlled by changing the size of the MaxRows value.

#include <stdio.h> #include <cstdlib>//Add dependent header file void Main () {int I,j,k;int maxRows = 12;//controls the size of the diamond// First, print the top four lines for (i=1;i<maxrows;i++) {for (j=1;j<maxrows-i;j++)//control the number of spaces to print printf (""); for (k=1;k<=2*i-1;k++)// Controls the number of asterisks to print printf ("*");p rintf ("\ n");} Print the bottom three lines for (i=1;i<=maxrows-2;i++) {for (j=1;j<=i;j++)//control the number of spaces to print printf (""); for (k=1;k<= (maxrows-i) * 2-3; k++)//control the number of asterisks to print printf ("*");p rintf ("\ n");} System ("pause");//For display please press the random key to continue ... so that the program will not quit a bit. }



Print a diamond code of a specified size under a C + + command prompt form

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.