#include <stdio.h>#include <string.h>int main(){char Display[31] = { 0 };//輸出字串int model[10] = { 0 };//位元模int code[10] = { 63, 6, 91, 79, 102, 109, 125, 7, 127, 111 };//十進位數模for (int i = 0; i < 10; i++){memset(model, 0, sizeof(model));memset(Display, 0, sizeof(Display));int j = 0, temp = code[i];while (temp)//計算位元模{model[j] = temp % 2;temp /= 2;j++;}printf("*******%d********\n", i);for (int k = 0; k < 10; k++)//輸出位元模{printf("%d", model[k]);}printf("\n");for (int k = 0; k < 10; k++){if (model[k] == 1)//根據位元模,描繪字串{switch (k){case 0:{for (int d = 0; d < 6; d++){Display[d] = i + '0';}break;}case 1:{Display[5] = i + '0';Display[11] = i + '0';Display[17] = i + '0';break;}case 2:{Display[17] = i + '0';Display[23] = i + '0';Display[29] = i + '0';break;}case 3:{for (int d = 24; d < 30; d++){Display[d] = i + '0';}break;}case 4:{Display[12] = i + '0';Display[18] = i + '0';Display[24] = i + '0';break;}case 5:{Display[0] = i + '0';Display[6] = i + '0';Display[12] = i + '0';break;}case 6:{for (int d = 12; d < 18; d++){Display[d] = i + '0';}break;}default:break;}}}for (int d = 0; d < 30; d++)//輸出字串{printf("%c", Display[d]);if (d % 6 == 5)printf("\n");}printf("\n");}getchar();return 0;}
輸出範例: