Based on the number of rows entered and the number of columns in the screen output diamond pattern

Source: Internet
Author: User

/* Program Run Result:

1234567

1 #

2 # # #

3 #####

4 #######

5 #####

6 # # #

7 #

*/

#include <stdio.h>

#include <stdlib.h>

void Diamond (int, int, char);

int Main (void)

{

Diamond (7, 7, ' # '); // print a diamond pattern with 7 rows of 7 columns # word arrangement

return0;

}

void Diamond (int line, int col, char ch)

{

int I, J, key, Space, count;

key = col/ 2 + 1  ; // Store the center value of the number of diamond columns

for(i = 1; I <= col; i++)

{

space = ABS (KEY-I); // store number of spaces per line

for(j = 1; J <= Space; j + +)

printf ("");

count = col-space * 2  ; // store number of # words per line

while(count)

{

printf ("%c", ch);

--count;

}

printf ("\ n");

}

return;

}

Based on the number of rows entered and the number of columns in the screen output diamond pattern

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.