[PAT B1036] together to learn programming with Obama

[PAT B1036] together to learn programming with Obama

US President Barack Obama not only appeal to everyone to learn programming, and even set an example to write code, write computer code to become the first president in American history. The end of 2014, to celebrate the "Computer Science Education Week" was officially launched, Obama wrote the computer code is very simple: draw a square on the screen. Now you draw it with him!
Input format:
input square side length N is given in a row (3 <= N <= 20 ) consisting of a square side and a certain character C, a space interval.
Output format:
Output the character C is drawn by a given square. But noted that the line spacing is larger than the column spacing, so in order to make the results look more like a square, the number of lines we output is actually 50% of the number of columns (rounded to the nearest integer).
Sample input:
10 A
sample output:
aaaaaaaaaaa
A A
A A
A A
aaaaaaaaaaa

#include <stdio.h>
#include "math.h"

int main() {
    int col, row;
    char symbol;
    scanf("%d %c", &col, &symbol);
    row = (int) round(col / 2);
    for (int i = 0; i < row; i++) {
        if (i == 0 || i == (row - 1)) {
            for (int j = 0; j < col; j++)
                printf("%c", symbol);
        } else {
            for (int j = 0; j < col; j++)
                if (j == 0 || j == (col - 1))
                    printf("%c", symbol);
                else
                    printf(" ");
        }
        printf("\n");
    }
}

Test Results:
Here Insert Picture Description

Published 33 original articles · won praise 1 · views 4154

Guess you like

Origin blog.csdn.net/qq_39827677/article/details/103855254