PAT Group Programming Ladder-practice set l1-015. Draw a square with Barack Obama

Source: Internet
Author: User

President Barack Obama has not only called on everyone to learn to program, or even to lead by example, to become the first president in American history to write computer code. At the end of 2014, to celebrate the official launch of computer Science Week, Obama wrote a very simple computer code: Draw a square on the screen. Now you draw with him, too!

Input format:

The input gives the square edge length N (3<=n<=21) in a row and a character c that makes up a square edge, spaced by a space.

Output format:

Outputs a square drawn by a given character C. But notice that the row spacing is larger than the column spacing, so to make the result look more like a square, the number of rows we output is actually 50% of the number of columns (rounded rounding).

Input Sample:
Ten A
Sample output:
Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

1#include <iostream>2#include <cstring>3#include <stdio.h>4 using namespacestd;5 intMain ()6 {7     intn,i,j;8     CharC;9Cin>>n>>C;Ten     intm; One     if(n%2==0) m=n/2; A     Else if(n%2!=0) m=n/2+1; -      for(i=1; i<=m;i++) -     { the          for(j=1; j<=n;j++) -         { -cout<<C; -         } +cout<<Endl; -     } +     return 0; A}

PAT Group Programming Ladder-practice set l1-015. Draw a square with Barack Obama

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.