复制代码
1 //-----------------------------------1
2 #include
3 #include
4 void main()
5 {
6 int value = 5;
7
8 printf("%01d\n", value);
9 printf("%02d\n", value);
10 printf("%03d\n", value);
11 printf("%04d", value);
12 getchar();
13 getchar();
14 getchar();
15 getchar();
16 }
17 //--------------------------------2
1 #include
2 int main(void)
3 {
4 double a = 50.00, b = 3.00, y = 0.00, m = 0.00, u = 0.00, c = 0.00;
5 scanf("%lf", &c);
6 y = a + c;
7 m = y/b;
8 u = a/m;
9 printf("%lf\n", u);
10 return 0;
11 }
1 graphics代码
2 #include "graphics.h"
3 #include "conio.h"
4 #include "easyx.h"
5 ht(int x,int y)
6 {
7 setcolor(YELLOW);
8 setfillcolor(BLUE);
9 fillcircle(x,y,20);
10 Sleep(500);
11 setcolor(BLACK);
12 setfillcolor(BLACK);
13 fillcircle(x,y,20);
14 }
15 void main()
16 {
17 initgraph(640,480); //(x,y) 只要有一个变量等于定值时开始反弹、x=0、x=460、y=620、y=0
18 int flagx=0,flagy=0; //用来标记 球走的方向 (0,0)向右下、(1,0)左下、(0,1)右上、(1,1)左上
19 int x=0,y=0;
20 while (1)
21 {
22
23 switch(flagx)
24 {
25 case 0:
26 {
27 switch(flagy)
28 {
29 case 0:{
30
31 x+=20;
32 y+=20;
33 ht(x,y);
34 if (x=620)
35 {
36 flagx=0;
37 flagy=1;
38 }
39 if (y=460)
40 {
41 flagy=1;
42 flagx=0;
43 }
44 }break;
45 case 1:{
46 x+=20;
47 y-=20;
48 ht(x,y);
49 if (x=0)
50 {
51 flagy=0;
52 flagx=0;
53 }
54
55 if (y=460)
56 {
57 flagy=1;
58 flagx=1;
59 }
60 }break;
61 }
62 }
//代码效果参考:http://www.zidongmutanji.com/zsjx/587639.html
63 case 1:
64 {
65 switch(flagy)
66 {
67 case 0:{
68
69 x+=20;
70 y-=20;
71 ht(x,y);
72 if (y=460)
73 {
74 flagx=1;
75 flagy=1;
76 }
77 if (x=0)
78 {
79 flagy=0;
80 flagx=0;
81 }
82 }break;
83 case 1:{
84 x-=20;
85 y-=20;
86 ht(x,y);
87 if (x=0)
88 {
89 flagy=1;
90 flagx=0;
91 }
92
93 if (y=0)
94 {
95 flagy=0;
96 flagx=1;
97 }
98 }break;
99 }
100
101 }
102
103 }
104 }
105 getch();
106 closegraph();
107 }
18 #include
19 #include
20 #include
21
22 void main()
23 {
24 char letter; // Letter typed by the user
25
26 printf("Do you want to continue? (Y/N): ");
27
28 letter = getch(); // Get the letter
29 letter = toupper(letter); // Convert letter to uppercase
30
31 while ((letter != 'Y') && (letter != 'N'))
32 {
33 putch(7); // Beep the speaker
34 letter = getch(); // Get the letter
35 letter = toupper(letter); // Convert letter to uppercase
36 }
37
38 printf("\nYour response was %c\n", letter);
39 /putch()向屏幕输出字符的函数
40 使用方式:
41 ① putch('转义字符');
42 ② putch('单个字符');
43 ③ putch(字符变量);
44 注:③需先定义 char 字符变量='单个字符';
45 头文件:conio.h
46 -----
47 putchar()在stdout上输出字符的宏
48 原形:int putchar(int c)
49 返回值:成功返回字符c,失败返回EOF。
50 头文件:stdio.h,7是响铃的意思/
51 }//代码效果参考:http://www.zidongmutanji.com/zsjx/333389.html
52 //-------------------------------------------3
53 #include
54
55 void main()
56 {
57 char letter;
58
59 int vowel_count = 0;
60
61 for (letter = 'A'; letter <= 'Z'; letter++)
62 switch (letter) {
63 case 'A':
64 case 'E':
65 case 'I':
66 case 'O':
67 case 'U': vowel_count++;
68 };
69
70 printf("The number of vowels is %d\n", vowel_count);
71 }
72 //------------------------------------------4
73 #include
74
75 void main()
76 {
77 int counter;
78
79 for (counter = 1; counter <= 100; counter++)
80 {
81 if (counter == 50)
82 break;
83
84 printf("%d ", counter);
85 }
86
87 printf("\nNext loop\n");
88
89 for (counter = 100; counter >= 1; counter--)
90 {
91 if (counter == 50)
92 break;
93
94 printf("%d ", counter);
95 }
96 }