C language basics, C Language
For example:
At first glance, I thought of printing numbers first and then combining them to form a combination of numbers.
First of all, I wonder if I can use a for loop for control. After all, a number on a computer is composed of plum blossom and space, like this code.
void print1() { int i, j; for (i = 0;i < 6; i++) printf(" *\n"); printf("\n");}void print2() { int i, j; for (i = 0; i < 6; i++) printf("*"); for (i = 0; i < 4; i++) { printf("\n"); for (j = 0; j < 4 - i; j++) printf(" "); printf("*"); }printf("\n"); for (i = 0; i < 6; i++) printf("*"); printf("\n");}
You can also input and print numbers one by one. However, the combined output of multiple numbers cannot be completed. It can only look at the array, a number is a two-dimensional array, multiple numbers form a three-dimensional array. So the code can be written like this!
#include<stdio.h>#include<string.h>int main(){ char b[100], a[10][5][6] = { ' ', ' ', '*', '*', ' ', ' ', ' ', '*', ' ', ' ', '*', ' ', ' ', '*', ' ', ' ', '*', ' ', ' ', '*', ' ', ' ', '*', ' ', ' ', ' ', '*', '*', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ', ' ', ' ', '*', '*', ' ', ' ', ' ', '*', ' ', ' ', '*', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ', ' ', '*', '*', '*', '*', ' ', ' ', '*', '*', '*', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ', '*', '*', '*', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ', '*', '*', '*', ' ', ' ', '*', ' ', ' ', ' ', ' ', ' ', '*', ' ', '*', ' ', ' ', ' ', '*', '*', '*', '*', '*', ' ', ' ', ' ', '*', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ','*', '*', '*', ' ', ' ', ' ', '*', ' ', ' ', ' ', ' ', ' ', '*', '*', '*', ' ', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', '*', '*', '*', ' ', ' ', ' ', ' ', ' *', '*', '*', ' ', ' ', '*', ' ', ' ', ' ', ' ', ' ', '*', '*', '*', '*', ' ', ' ', '*', ' ', ' ', '*', ' ', ' ', '*', '*', '*', '*', ' ', ' ', '*', '*', '*', '*', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', '*', '*', '*', ' ', ' ', '*', ' ', ' ', ' ', '*', ' ', ' ', ' ', '*', ' ', ' ', ' ', '*', ' ', ' ', ' ', '*', ' ', ' ', '*', '*', '*', ' ', ' ', ' ', '*', '*', '*', ' ', ' ', '*', ' ', ' ', ' ', '*', ' ', ' ', ' ', '*', '*', '*', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ', ' ', ' ', '*', ' ' }; int i, j, k, n = 0; gets_s(b); n = strlen(b); for (j = 0; j < 5; j++) { for (k = 0; k < n; k++) { if (b[k] == '0') for (i = 0; i < 6; i++) printf("%c", a[0][j][i]); if (b[k] == '1') for (i = 0; i < 6; i++) printf("%c", a[1][j][i]); if (b[k] == '2') for (i = 0; i < 6; i++) printf("%c", a[2][j][i]); if (b[k] == '3') for (i = 0; i < 6; i++) printf("%c", a[3][j][i]); if (b[k] == '4') for (i = 0; i < 6; i++) printf("%c", a[4][j][i]); if (b[k] == '5') for (i = 0; i < 6; i++) printf("%c", a[5][j][i]); if (b[k] == '6') for (i = 0; i < 6; i++) printf("%c", a[6][j][i]); if (b[k] == '7') for (i = 0; i < 6; i++) printf("%c", a[7][j][i]); if (b[k] == '8') for (i = 0; i < 6; i++) printf("%c", a[8][j][i]); if (b[k] == '9') for (i = 0; i < 6; i++) printf("%c", a[9][j][i]); } printf("\n"); } return 0; }
The problem is solved !~