[C] Implementation Method for printing the diamond pattern and printing the diamond pattern

Source: Internet
Author: User

[C] Implementation Method for printing the diamond pattern and printing the diamond pattern

Method 1: Split the diamond into two parts and print the content above and below in sequence.

Source code:

#include<stdio.h>
Int main()
{
     / / First write the upper part of the diamond
     Int line = 0;
     Printf ("Please enter the number of lines");
     Scanf("%d",&line);
     / / According to the pattern, to output the upper part of the diamond, you need to use the for loop, loop output line output each line
     //on
     Int i = 0;
     For(i=0;i<line;i++){
         / / Each line first outputs a space, and then output *
         Int j = 0;
         / / Output space
         For(j=0;j<line+1-i;j++){
             Printf(" ");
         }
         //output*
         For(j=0;j<2*i-1;j++){
             Printf("*");
         }
         Printf("\n");
     }
     //under
     For(i=0;i<line-1;i++){
         Int j = 0;
         For(j=0;j<i+1;j++){
             Printf(" ");
         }
         For(j=0;j<2*(line-1-i)-1;j++){
             Printf("*");
         }
         Printf("\n");
     }
     Return 0;
}


Related Article

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.