Skip to content

Instantly share code, notes, and snippets.

@Wonicon
Created January 30, 2017 06:55
Show Gist options
  • Save Wonicon/cf1281ee2774233626749ae6d602643f to your computer and use it in GitHub Desktop.
Save Wonicon/cf1281ee2774233626749ae6d602643f to your computer and use it in GitHub Desktop.
Basic programming questions
/**
* 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