《C程序设计语言现代方法》第5章 编程题

《C程序设计语言现代方法》第5章 编程题

1 编写一个程序,确定一个数的位数。

1 #include <stdio.h> main() 4 { 5int a, cnt = 0;(scanf(, &a) == 1) 8 { 9cnt++;10 }, cnt);;14 }

注:在Windows下,输入完毕后先按Enter键,再按CTRL+Z键,最后再按Enter键,即可结束输入。在Linux下,输入完毕后按CTRL+D键即可结束输入。

2 编写一个程序,香港虚拟主机,要求用户输入24小时制的时间,然后显示12小时制的时间格式:

Enter a 24-hour time: 21:11

Equivalent 12-hour time: 9:11 PM

注意不要把12:00显示成0:00

1 #include <stdio.h> main() 4 { 5int h, m;);, &h, &m); 9if (h > 23 || h < 0 || m > 59 || m < 0)); {);14if (h > 12), h%12, m);printf(, h, m);18 };21 }

运行结果如下:

7 编写一个程序,从用户输入的4个整数中找出最大值和最小值。

Enter four integers: 21 43 10 45

Largest: 43

Smallest: 10

要求尽可能少用if语句。

9 编写一个程序,网站空间,香港虚拟主机,提示用户输入两个日期,然后显示哪一个日期更早:

Enter first date (mm/dd/yy) : 3/6/08

Enter second date (mm/dd/yy) : 5/17/07

5/17/07 is earlier than 3/6/08

11 编写一个程序,要求用户输入一个两位数,然后显示该数的英文单词:

Enter a two-digit number : 45

You entered the number forty-five

posted on

不要轻言放弃,否则对不起自己

《C程序设计语言现代方法》第5章 编程题

相关文章:

你感兴趣的文章:

标签云: