Posted on 2005-08-28 17:02
这里的黄昏静悄悄 阅读(622)
评论(0) 编辑 收藏 引用 所属分类:
C/C++
效果图如下,代码附后
要求,输入第一个数字n,0<n<20,第二个为要显示的数字,要求输出第二个数字,并且每个数字要求占n+2列2n+3行
1 /*--------------------------------------------------------------------
2 * filename : digitdisplay.c
3 * Discribe : display a number
4 * Author : JackRain
5 * Date : 08--28--2005
6 * E_mail : jack.fandlr@gmail.com
7 * Test with C-Free 3.5
8 *-------------------------------------------------------------------*/
9
10 #include <stdio.h>
11
12
13 int main()
14 {
15 static int digittab[10][2]={{5,0xF},//0
16 {0,0x5},//1
17 {7,0x6},//2
18 {7,0x5},//3
19 {2,0xD},//4
20 {7,0x9},//5
21 {7,0xB},//6
22 {4,0x5},//7
23 {7,0xF},//8
24 {7,0xD}};//9
25 int i,n,j=0,strline;
26 char *p,code1= ' ',code2= ' ',code3 = ' ',a1 = ' ',a2= ' ',a3= ' ',a4= ' ';
27 char cA[15];
28 printf("Please input two numbers:");
29 scanf("%d %s",&n,cA);
30 p = cA;
31 // output the first line
32 while(*(p+j) != '\0')
33 {
34 printf(" ");
35 if(digittab[*(p+j)-'0'][0]&4)
36 code1 = '-';
37 else
38 code1 = ' ';
39 for(strline = 0; strline < n; strline++)
40 printf("%c",code1);
41 printf(" ");
42 j++;
43 }
44 printf("\n");
45 // out put 2~ n+1 lines
46 for(i = 0; i < n; i++)
47 {
48 j = 0;
49 while(*(p+j)!='\0')
50 {
51 a1 = ' ';
52 a2 = ' ';
53 switch(digittab[*(p+j)-'0'][1]&0xC)
54 {
55 case 0xC:a2='|';
56 case 0x8: a1 = '|';break;
57 case 0x4: a2 = '|';break;
58 }
59 printf("%c",a1);
60 for(strline = 0; strline < n; strline++)
61 printf(" ");
62 printf("%c ",a2);
63 j++;
64 }
65 printf("\n");
66 }
67 // output the middle line
68 j = 0;
69 while(*(p+j) != '\0')
70 {
71 printf(" ");
72 if(digittab[*(p+j)-'0'][0]&2)
73 code2 = '-';
74 else
75 code2 = ' ';
76 for(strline = 0; strline < n;strline++)
77 printf("%c",code2);
78 printf(" ");
79 j++;
80
81 }
82 printf("\n");
83 // output n+4~ 2n+2 lines
84 for(i = 0; i< n;i++)
85 {
86 j=0;
87 while(*(p+j)!='\0')
88 {
89 a3 = ' ';
90 a4 = ' ';
91 switch(digittab[*(p+j)-'0'][1]&3)
92 {
93 case 3: a3 = '|';
94 case 1: a4= '|';break;
95 case 2: a3= '|';break;
96 }
97 printf("%c",a3);
98 for(strline = 0; strline<n;strline++)
99 printf(" ");
100 printf("%c",a4);
101 printf(" ");
102 j++;
103 }
104 printf("\n");
105 }
106 // output the last line
107 j=0;
108 while(*(p+j) != '\0')
109 {
110 if(digittab[*(p+j)-'0'][0]&1)
111 {
112 code3='-';
113 }
114 else
115 code3 = ' ';
116 printf(" ");
117 for(strline = 0 ; strline < n; strline++)
118 printf("%c",code3);
119 printf(" ");
120 j++;
121 }
122 printf("\n");
123 return 0;
124 }