/*C Primer Plus (5.10) 9*/

 1 #include<stdio.h>
2 #define G 103
3 int main()
4 {
5 char ch=96;
6
7 while(ch++<G)
8 {
9 printf("%5c",ch);
10 }
11 printf("\n");
12
13 return 0;
14 }

/*C Primer Plus (5.11) 1*/

 1 #include<stdio.h>
2 #define M_TO_H 60
3 int main()
4 {
5 int time;
6 int hour=0,minute=0;
7
8 printf("Please enter the time(mins)\n");
9 printf("Enter 0 or num<0 to quit.\n");
10 printf("Your time:");
11 scanf("%d",&time);
12 while(time>0)
13 {
14 hour=time/M_TO_H;
15 minute=time%M_TO_H;
16 printf("%d mintues is %d hours and %d minutes\n",time,hour,minute);
17 printf("Please enter again!\n");
18 printf("Your time:");
19 scanf("%d",&time);
20 }
21 printf("Done!");
22
23 return 0;
24 }
25 /*
26 輸出樣例
27
28 Please enter the time(mins)
29 Enter 0 or num<0 to quit.
30 Your time:20
31 20 mintues is 0 hours and 20 minutes
32 Please enter again!
33 Your time:60
34 60 mintues is 1 hours and 0 minutes
35 Please enter again!
36 Your time:85
37 85 mintues is 1 hours and 25 minutes
38 Please enter again!
39 Your time:0
40 Done!
41
42 */

/*C Primer Plus (5.11) 2*/

 1 #include<stdio.h>
2 int main()
3 {
4 int num;
5 int i=0;
6
7 printf("Please enter an integer:");
8 scanf("%d",&num);
9 printf("You will get %d to %d\n",num,num+10);
10 printf("%d\t",num);
11 while(i<10)
12 {
13 ++num;
14 i++;
15 printf("%d\t",num);
16 }
17
18 return 0;
19 }
20 /*
21 輸出樣例
22
23 Please enter an integer:5
24 You will get 5 to 15
25 5 6 7 8 9 10 11 12 13 14 15
26
27 */

/*C Primer Plus (5.11) 3*/

 1 #include<stdio.h>
2 #define D_TO_W 7
3 int main()
4 {
5 int days;
6 int week=0,day=0;
7
8 printf("Please enter the number of days(<=0 to quit):");
9 scanf("%d",&days);
10 while(days>0){
11 week=days/D_TO_W;
12 day=days%D_TO_W;
13 printf("%d days is %d weeks, %d days\n",days,week,day);
14 printf("Now enter the number of days again:");
15 scanf("%d",&days);
16 }
17 printf("You have quitted just now.");
18
19 return 0;
20 }
21 /*
22
23 輸出樣例
24
25 Please enter the number of days(<=0 to quit):18
26 18 days is 2 weeks, 4 days
27 Now enter the number of days again:24
28 24 days is 3 weeks, 3 days
29 Now enter the number of days again:35
30 35 days is 5 weeks, 0 days
31 Now enter the number of days again:0
32 You have quitted just now.
33
34 */

/*C Primer Plus (5.11) 4*/

 1 #include<stdio.h>
2 #define CM_TO_IN 0.3937 //1cm=0.3937inch
3 #define CM_TO_ML 0.0328 //1cm=0.0328inch
4 int main()
5 {
6 float height;
7 float inch=0,feet=0;
8
9 printf("Enter a height in centimeters:");
10 scanf("%f",&height);
11 while(height>0)
12 {
13 feet=(int)(height*CM_TO_ML);
14 inch=(height-(feet/CM_TO_ML))*CM_TO_IN;
15 printf("%.1f cm=%d feet, %3.1f inches\n",height,(int)feet,inch);
16 printf("Enter a height in centimeters(<=0 to quit):");
17 scanf("%f",&height);
18 }
19 printf("bye.");
20
21 return 0;
22 }
23 /*
24 Sample Output
25
26 Enter a height in centimeters:182
27 182.0 cm=5 feet, 11.6 inches
28 Enter a height in centimeters(<=0 to quit):168.7
29 168.7 cm=5 feet, 6.4 inches
30 Enter a height in centimeters(<=0 to quit):0
31 bye.
32
33 */

/*C Primer Plus (5.11) 5*/

 1 #include<stdio.h>
2 int main()
3 {
4 int count,sum;
5 int i=0;
6
7 count=0;
8 sum=0;
9 printf("Please enter the days you work: ");
10 scanf("%d",&i);
11 while(count++<i)
12 {
13 sum+=count;//sum=sum+count;
14 }
15 printf("Sum=%d\n",sum);
16 printf("That all!");
17
18 return 0;
19 }
20 /*
21 Sample Output
22
23 Please enter the days you work: 20
24 Sum=210
25 That all!
26
27 */

/*C Primer Plus (5.11) 6*/

 1 #include<stdio.h>
2 int main()
3 {
4 int count,sum;
5 int i=0;
6
7 count=0;
8 sum=0;
9 printf("Please enter the days you work: ");
10 scanf("%d",&i);
11 while(count++<i)
12 {
13 sum+=count*count;//sum=sum+(count*count)
14 }
15 printf("Sum=%d\n",sum);
16 printf("That all!");
17
18 return 0;
19 }
20 /*
21 Sample Output
22
23 Please enter the days you work: 20
24 Sum=2870
25 That all!
26
27 */

/*C Primer Plus (5.11) 7*/

 1 #include<stdio.h>
2 double fun(double x)
3 {
4 printf("The cube of the number is:%g",x*x*x);
5 return x;
6 }
7 int main()
8 {
9 double num;
10
11 printf("Please enter a number:");
12 while(scanf("%lf",&num)==1)
13 {
14 fun(num);
15 printf("\n");
16 printf("Please enter another number:");
17 }
18 printf("You enter a wrong data,the program has been quit.");
19 return 0;
20 }
21 /*
22 Sample Output
23
24 Please enter a number:3
25 The cube of the number is:27
26 Please enter another number:2
27 The cube of the number is:8
28 Please enter another number:5
29 The cube of the number is:125
30 Please enter another number:p
31 You enter a wrong data,the program has been quit.
32
33 */

/*C Primer Plus (5.11) 8*/

 1 #include<stdio.h>
2 int main()
3 {
4 int num1,num2;
5 int mod=0;
6
7 printf("This program computes moduli.\n");
8 printf("Enter an integer to serve as the second operand:");
9 scanf("%d",&num1);
10 printf("Now enter the first operand:");
11 while(scanf("%d",&num2)==1)
12 {
13 mod=num2%num1;
14 if(num2==0)
15 break;
16 printf("%d %% %d is %d\n",num2,num1,mod);
17 printf("Enter next number for first operand (<=0 to quit):");
18 }
19 printf("Done.");
20
21 return 0;
22 }
23 /*
24 Sample Output
25
26 This program computes moduli.
27 Enter an integer to serve as the second operand:256
28 Now enter the first operand:438
29 438 % 256 is 182
30 Enter next number for first operand (<=0 to quit):1234567
31 1234567 % 256 is 135
32 Enter next number for first operand (<=0 to quit):0
33 Done.
34
35 */

/*C Primer Plus (5.11) 9*/

 1 #include<stdio.h>
2
3 double Temperatures(double x)
4 {
5 const double F_TO_C=32.0;
6 const double C_TO_K=273.16;
7 double c=0,k=0;
8 c=5.0/9.0*(x-F_TO_C);
9 k=c+C_TO_K;
10 printf("Centigrade temperature:%.3lf\n",c);
11 printf("Kelvin temperature:%.3lf\n",k);
12 }
13
14 int main()
15 {
16 double temp=0;
17
18 printf("Please enter temperatures in Degree Fahrenheit:");
19 while(scanf("%lf",&temp)==1)
20 {
21 printf("Fahrenheit temperature:%.3lf\n",temp);
22 Temperatures(temp);
23 printf("Please enter temperatures in Degree Fahrenheit (enter q and other non-numeric characters to quit):");
24 }
25 printf("Done.");
26 return 0;
27 }
28 /*
29 Sample Output
30
31 Please enter temperatures in Degree Fahrenheit:77
32 Fahrenheit temperature:77.000
33 Centigrade temperature:25.000
34 Kelvin temperature:298.160
35 Please enter temperatures in Degree Fahrenheit (enter q and other non-numeric characters to quit):98
36 Fahrenheit temperature:98.000
37 Centigrade temperature:36.667
38 Kelvin temperature:309.827
39 Please enter temperatures in Degree Fahrenheit (enter q and other non-numeric characters to quit):q
40 Done.
41
42 */

C Primer Plus 5.11 編程練習的更多相关文章

  1. C Primer Plus (6.16) 編程練習

    /*C Primer Plus (6.15) 6*/ 1 #include<stdio.h> 2 int main() 3 { 4 int i,j; 5 for(int i=0;i< ...

  2. C Primer Plus(4.8)編程練習

    /*C Primer Plus (4.7) 5*/ 1 include<stdio.h> 2 #define BOOK "War and Peace" 3 int ma ...

  3. [转] 編程風格要素-The Elements of Programming Style 中文英文中英對照

    转自: http://www.loliman3000.com/tech/2fe33ce32906f0302412881.php 下面的程序風格規則提煉自Brian Kernighan和P. J. Pl ...

  4. C++編程札記「基礎」

    一直以為自己最擅長的編程語言是C++,那時自己的水平停留在使用C++來實現數據結構中的各種ADT和ACM算法. 創建一個類,必須實現的成員函數 explicit構造函數 對於單參數構造函數,添加exp ...

  5. [心得] 如何利用liquibase進行資料庫版本控制 - 實際練習

    透過上一篇的基本觀念介紹,希望大家應該有一點點感覺了! 這篇我們就來做個簡單的版本演練,加深印象吧! 我使用的環境如下 System : Windows 7 Database : SQL Server ...

  6. [转]2010 Ruby on Rails 書單 與 練習作業

    原帖:http://wp.xdite.net/?p=1754 ========= 學習 Ruby on Rails 最快的途徑無非是直接使用 Rails 撰寫產品.而這個過程中若有 mentor 指導 ...

  7. [Java] 練習用對戰小遊戲

    繼承.介面自我練習時所建立的小遊戲,一開始輸入名稱來建立對戰腳色,之後以輸入招式號碼的方式互相打鬥,最後沒血的一方就輸了. 人物種族 abstract public class Human { int ...

  8. 《C++ primer》--第11章

    习题11.1 algorithm头文件定义了一个count的函数,其功能类似于find.这个函数使用一对迭代器和一个值做参数,返回这个值出现次数的统计结果.编写程序读取一系列int型数据,并将它们存储 ...

  9. C++ Primer 5th 第11章 关联容器

    练习11.1:描述map 和 vector 的不同. map是关联容器,vector是顺序容器,关联容器与值无关,vector则与值密切相关 练习11.2:分别给出最适合使用 list.vector. ...

随机推荐

  1. 6.Git忽略文件

    忽略指定文件 有些文件与实际功能无关,不参与服务器上部署运行,把他们忽略调能够屏蔽ide工具之间的差异 1.在工作区目录下创建xxx.gitignore文件 (前缀名随意) 以斜杠"/&qu ...

  2. 10.pygame-碰撞检测

    添加并监听英雄发射子弹事件 class Hero(GameSprite): def __init__(self): # 调用父类方法,设置image super().__init__('./image ...

  3. Workflow,要不要了解一下

    摘要:Workflow本质是开发者基于实际业务场景开发用于部署模型或应用的流水线工具. Workflow(也称工作流,下文中均可使用工作流进行描述)本质是开发者基于实际业务场景开发用于部署模型或应用的 ...

  4. PMM实现监控Mysql-MGR

    一.docker安装PMM服务端 1.安装yum配置单元 # 如果已安装,略过此步 yum install -y yum-utils #yum配置单元 2.配置docker阿里云yum源 #配置doc ...

  5. java学习之Servlet

    0x00前言 Servlet就是一个接口我们需要写一个类然后去实现Servlet,就可以被服务器识别到.request是用来接受客户端传过来的参数,respone是用来响应客户端的页面.我们所用的容器 ...

  6. 删除redis对应key的缓存

    [root@zhyly-pre-002 ~]# /usr/local/redis/bin/redis-cli -p 6379 #登录redis 127.0.0.1:6379> auth 'Red ...

  7. Go语言核心36讲21

    提到Go语言中的错误处理,我们其实已经在前面接触过几次了. 比如,我们声明过error类型的变量err,也调用过errors包中的New函数.今天,我会用这篇文章为你梳理Go语言错误处理的相关知识,同 ...

  8. 周立功DTU+温度传感器,ZWS物联网平台尝试

    1.前言 了解到周立功有相关的物联网云平台,近期在调研动态环境监控项目,可以进行一个上云的尝试.购置了传感器.周立功的DTU等硬件,将传感器的温度.湿度等数据进行一个云平台的上传. 2.前期准备 传感 ...

  9. Google地图瓦片

    1.Web墨卡托空间参考 1.1.什么是Web墨卡托 墨卡托投影,又称正轴等角圆柱投影,由荷兰地图学家墨卡托(G.Mercator)于1569年创拟.假设地球被套在一个圆柱中,赤道与圆柱相切,然后在地 ...

  10. 下载安装MinGW-w64详细步骤

    一.MinGW-w64介绍 MinGW 的全称是:Minimalist GNU on Windows ,实际上是将gcc(c/c++编译器)移植到了 Windows 平台下,并且包含了 Win32AP ...