Created
January 30, 2017 06:55
-
-
Save Wonicon/cf1281ee2774233626749ae6d602643f to your computer and use it in GitHub Desktop.
Basic programming questions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Question: https://www.zhihu.com/question/55234202 | |
* Usage: <proc> <lines> | |
* Example: ./a.out 6 | |
* A | |
* ABA | |
* ABCBA | |
* ABCDCBA | |
* ABCDEDCBA | |
* ABCDEFEDCBA | |
*/ | |
#include <stdio.h> | |
#include <stdlib.h> | |
void print(int lines) | |
{ | |
int blanks = lines - 1; | |
char ch = 'A'; | |
for (int line = 0; line < lines; line++) { | |
for (int i = 0; i < blanks; i++) { | |
putchar(' '); | |
} | |
for (int i = 0; i <= line; i++) { | |
putchar(ch + i); | |
} | |
for (int i = line - 1; i >= 0; i--) { | |
putchar(ch + i); | |
} | |
putchar('\n'); | |
blanks--; | |
} | |
} | |
int main(int argc, char *argv[]) | |
{ | |
print(atoi(argv[1])); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment