/* Your task is to print a number of single-digit integers inside a border of asterisks. The input will consist of a list of integers that need to be printed within the border. There will also be a number indicating how many integers should be placed per line inside the border. The input is formatted as follows. The first line contains a number N indicating the number of single-digit integers that will follow. The second line contains N single-digit integers that will need to be printed. The third line contains only one number L that indicates how many integers can be printed per line. If L < N then the integers must be placed on multiple lines within the border. If L does not divide N evenly, then the last line of the output will have less than L numbers. You can assume that N and L will always be greater than or equal to 1. Make sure that a single space (either horizontal or vertical) separates the border from the numbers inside. Also, place a space between digits on the same line. Here are two sample test runs: ---------------- START OF INPUT ------------------------- 1 1 1 ---------------- END OF INPUT --------------------------- ---------------- START OF OUTPUT ------------------------ ***** * * * 1 * * * ***** ----------------- END OF OUTPUT ------------------------- ---------------- START OF INPUT ------------------------- 7 7 6 5 4 3 2 1 3 ---------------- END OF INPUT --------------------------- ---------------- START OF OUTPUT ------------------------ ********* * * * 7 6 5 * * 4 3 2 * * 1 * * * ********* ----------------- END OF OUTPUT ------------------------- */ void printStar() { putchar('*'); } int main() { int N, L; int i, l; int linesNeeded, index; scanf("%d", &N); int nums[N]; for(i = 0; i < N; ++i) scanf("%d", &nums[i]); scanf("%d", &L); // Print the top border for(i = 0; i < (3 + 2*L); ++i) printStar(); printf("\n"); printStar(); for(i = 0; i < (1 + 2*L); ++i) printf(" "); printStar(); printf("\n"); index = 0; linesNeeded = ceil(N * 1.0 / L); // Print each line of numbers for(l = 0; l < linesNeeded; ++l) { printStar(); printf(" "); for(i = 0; i < L; ++i) { if(index < N) printf("%d ", nums[index++]); else printf(" "); } printStar(); printf("\n"); } printStar(); for(i = 0; i < (1 + 2*L); ++i) printf(" "); printStar(); printf("\n"); // Print the bottom border for(i = 0; i < (3 + 2*L); ++i) printStar(); printf("\n"); //system("pause"); return 0; }