/*C Primer Plus (4.7) 5*/

 1 include<stdio.h>
2 #define BOOK "War and Peace"
3 int main(void)
4 {
5 float cost=12.99;
6 float percent=80.0;
7
8 printf("This copy of \"%s\" sells for $%.2f.\n",BOOK,cost);
9 printf("That is %.0f%% of list.",percent);/*打印%要這樣“%%”*/
10
11 return 0;
12 }
13 /*
14 輸出樣例:
15
16 This copy of "War and Peace" sells for $12.99.
17 That is 80% of list.
18
19 */

/*C Primer Plus (4.8) 1*/

 1 #include<stdio.h>
2 int main()
3 {
4 char firstname[30];
5 char lastname[30];
6
7 printf("Please enter your first name.\n");
8 printf("First name:");
9 scanf("%s",firstname);
10 printf("Please enter your last name.\n");
11 printf("Last name:");
12 scanf("%s",lastname);
13 printf("Hello! %s %s Welcome~!",firstname,lastname);
14
15 return 0;
16 }
17 /*
18 輸出樣例
19
20 Please enter your first name.
21 First name:Tomoko
22 Please enter your last name.
23 Last name:Kuroki
24 Hello! Tomoko Kuroki Welcome~!
25
26 */

/*C Primer Plus (4.8) 2*/

 1 #include<stdio.h>
2 #include<string.h>
3 int main()
4 {
5 char firstname[30];
6 char lastname[30];
7 int string1=0,string2=0;
8
9 printf("Please enter your first name.\n");
10 printf("First name:");
11 scanf("%s",firstname);
12 printf("Please enter your last name.\n");
13 printf("Last name:");
14 scanf("%s",lastname);
15 string1=strlen(firstname);
16 string2=strlen(lastname);
17 printf("Request 1:/*\"%s %s\"*/\n",firstname,lastname);
18 printf("Request 2:/*\"%20s %20s\"*/\n",firstname,lastname);
19 printf("Request 3:/*\"%-20s %-20s\"*/\n",firstname,lastname);
20 printf("Request 4:/*%*s %*s*/",string1+3,firstname,string2+3,lastname);
21
22 return 0;
23 }
24 /*
25 輸出樣例
26
27 //Please enter your first name.
28 //First name:Tomoko
29 //Please enter your last name.
30 //Last name:Kuroki
31 // Request 1:/*"Tomoko Kuroki"*/
32 // Request 2:/*" Tomoko Kuroki"*/
33 // Request 3:/*"Tomoko Kuroki "*/
34 // Request 4:/* Tomoko Kuroki*/

/*C Primer Plus (4.8) 3*/

 1 #include<stdio.h>
2 int main()
3 {
4 float num=0;
5
6 printf("Please enter a floating-point number:");
7 scanf("%f",&num);
8 printf("a:The input is %.1f or %.1e.\n",num,num);
9 printf("b:The input is %+.3f or %.3E.",num,num);
10
11 return 0;
12 }
13 /*
14 輸出樣例
15
16 Please enter a floating-point number:26.87
17 a:The input is 26.9 or 2.7e+001.
18 b:The input is +26.870 or 2.687E+001.
19
20 */

/*C Primer Plus (4.8) 4*/

 1 #include<stdio.h>
2 #define I_TO_F 0.08333
3 int main()
4 {
5 char name[30];
6 float height=0,realheight=0;
7
8 printf("Please enter your name and your height(inches).\n");
9 printf("Your name:");
10 scanf("%s",name);
11 printf("Your height:");
12 scanf("%f",&height);
13 realheight=height*I_TO_F;
14 printf("%s, you are %.3f feet tall.",name,realheight);
15
16 return 0;
17 }
18 /*
19 輸出樣例
20
21 Please enter your name and your height(inches).
22 Your name:Dabney
23 Your height:74.496
24 Dabney, you are 6.208 feet tall.
25
26 */

/*C Primer Plus (4.8) 5*/

 1 #include<stdio.h>
2 #define BIT 8
3 int main()
4 {
5 float file=0,speed=0,time=0;
6 printf("Please enter the net speed\n");
7 printf("The net speed:");
8 scanf("%f",&speed);
9 printf("Please enter the size of the file:\n");
10 printf("The size of flie:");
11 scanf("%f",&file);
12 time=file*BIT/speed;
13 printf("At %.2f megabits per seconds, a file of %.2f megabytes\n"
14 "downloads in %.2f seconds.",speed,file,time);
15
16 return 0;
17 }
18 /*
19 輸出樣例
20
21 Please enter the net speed
22 The net speed:18.123
23 Please enter the size of the file:
24 The size of flie:2.203
25 At 18.12 megabits per seconds, a file of 2.20 megabytes
26 downloads in 0.97 seconds.
27
28 */

/*C Primer Plus (4.8) 6*/

 1 #include<stdio.h>
2 #include<string.h>
3 int main()
4 {
5 char firstname[30];
6 char lastname[30];
7 int string1=0,string2=0;
8
9 printf("Please enter your first name.\n");
10 printf("First name:");
11 scanf("%s",firstname);
12 string1=strlen(firstname);
13 printf("Please enter your last name.\n");
14 printf("Last name:");
15 scanf("%s",lastname);
16 string2=strlen(lastname);
17 printf("%s %s\n",firstname,lastname);
18 printf("%*d %*d\n",string1,string1,string2,string2);
19 printf("%s %s\n",firstname,lastname);
20 printf("%-*d %-*d\n",string1,string1,string2,string2);
21
22 return 0;
23 }
24 /*
25 輸出樣例
26
27 Please enter your first name.
28 First name:Tomoko
29 Please enter your last name.
30 Last name:Kuroki
31 Tomoko Kuroki
32 6 6
33 Tomoko Kuroki
34 6 6
35
36 */

/*C Primer Plus (4.8) 7*/

 1 #include<stdio.h>
2 #include<float.h>
3 int main()
4 {
5 double double_value=1.0/3.0;
6 float float_value=1.0/3.0;
7
8 printf("Request1:float_value=%8f double_value=%8.6lf\n",float_value,double_value);
9 printf("\nRequest2:float_value=%8.12f double_value=%8.12lf\n",float_value,double_value);
10 printf("\nRequest3:float_value=%8.16f double_value=%8.16lf\n",float_value,double_value);
11 printf("\nfloat and double maximum significant digits:\n");
12 printf("FLT_DIG = %d, DBL_DIG = %d\n", FLT_DIG, DBL_DIG);
13 //FLT_DIG代表float有效十进制数字位数
14 //DBL_DIG代表double有效十进制数字位数
15
16 return 0;
17 }
18 /*
19 輸出樣例
20
21 Request1:num1=0.333333 num2=0.333333
22
23 Request2:num1=0.333333333333 num2=0.333333343267
24
25 Request3:num1=0.3333333333333333 num2=0.3333333432674408
26
27 float and double maximum significant digits:
28 FLT_DIG = 6, DBL_DIG = 15
29
30 */

/*C Primer Plus (4.8) 8*/

 1 #include<stdio.h>
2 #define G_TO_L 3.785f
3 #define M_TO_KM 1.609f
4 int main()
5 {
6 float miles=0,gallons=0;
7 float KM=0,L=0;
8 float Europe=0,USA=0;
9
10 printf("Please enter the travel journey(miles) and gas consumption(gallons).\n");
11 printf("Travel journey(in miles):");
12 scanf("%f",&miles);
13 printf("Gas consumption(in gallons):");
14 scanf("%f",&gallons);
15 KM=miles*M_TO_KM;
16 L=gallons*G_TO_L;
17 Europe=L/KM;
18 USA=miles/gallons;
19 printf("The USA program measures travel per unit of fuel consumed (higher values, better):"
20 "%.1f Miles/Gallons\n",USA);
21 printf("The European scheme measures the stroke per unit of fuel consumed (the smaller the value, the better):"
22 "%.1f L/KM",Europe);
23
24 return 0;
25 }
26 /*
27 輸出樣例
28
29 Please enter the travel journey(miles) and gas consumption(gallons).
30 Travel journey(in miles):62.137
31 Gas consumption(in gallons):2.1134
32 The USA program measures travel per unit of fuel consumed (higher values, better):29.4 Miles/Gallons
33 The European scheme measures the stroke per unit of fuel consumed (the smaller the value, the better):0.1 L/KM
34
35 */

C Primer Plus(4.8)編程練習的更多相关文章

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

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

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

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

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

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

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

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

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

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

  6. unix network programming volume1 sorce code build and get(UNIX網絡編程卷1第三版)

    source code下载地址:unpv13e.tar.gz下载 (也有放一份在google cloud storage) compile 1. ./configure 2. cd lib make ...

  7. gym101522 [小熊骑士限定]La Salle-Pui Ching Programming Challenge 培正喇沙編程挑戰賽 2017

    西瓜队(划掉),Kuma Rider久违的第一场训练,四小时瞎打.jpg A.水题,排序 #include<cstdio> #include<iostream> #includ ...

  8. Linux下串口編程遇到的接收数据错误及原因(0x0d,0x11接收错误)

    摘要:Linux下串口编程遇到的接收数据错误及原因 来源:https://dotblogs.com.tw/k/2012/07/24/73572 近日在调试串口的时候发现,另一设备向我ARM板的串口发送 ...

  9. JavaScript DOM 編程藝術(2版) 綜合實例Band js代碼

    function addLoadEvent(func){ var oldonload=window.onload; if(typeof window.onload!='function') { win ...

  10. 再次理解WCF以及其通信(附加一個編程小經驗)

    一.概述 Windows Communication Foundation(WCF)是由微软发展的一组数据通信的应用程序开发接口,可以翻译为Windows通讯接口,它是.NET框架的一部分.由 .NE ...

随机推荐

  1. NLP之TextLSTM(预测单词下一个字母)

    LSTM 目录 LSTM 1.理论 1.1 LSTM与RNN 1.1.1 RNN的缺点 1.1.2 LSTM 1.2 LSTM基本结构 2.实验 2.1 实验步骤 2.2 算法模型 1.理论 1.1 ...

  2. 【MySQL】Navicat15 安装

    # Navicat安装` 提示`:鉴于之间已经出了MySQL的安装教程,在这了我也讲下,那个其实包含了两个知识点,既可以小白初次安装MySQL客户端,也面向想安装5.x和8.x两个版本的. --- @ ...

  3. Docker中数据卷(Volume)的使用

    数据卷有两种形式,一种是容器中的某个目录,它可以被别的容器引用,只要有一个容器引用了这个数据卷,数据就不会被删除:另一种数据卷是将容器中的数据卷和宿主机的目录进行挂载. 数据卷可以在多个容器之间共享, ...

  4. ML-L1、L2 正则化

    出现过拟合时,使用正则化可以将模型的拟合程度降低一点点,使曲线变得缓和. L1正则化(LASSO) 正则项是所有参数的绝对值的和.正则化不包含theta0,因为他只是偏置,而不影响曲线的摆动幅度. \ ...

  5. Java 编码那些事(二)

    建议先阅读:Java 编码那些事(一) 现在说说编码在Java中的实际运用.在使用tomcat的时候,绝大部分同学都会遇到乱码的问题,查查文档,google一下解决方案啥的,都是设置这里,设置那里,或 ...

  6. HashMap基本使用方法

    HashMap Map集合基于 键(key)/值(value)映射.每个键最多只能映射一个值.键可以是任何引用数据类型的值,不可重复:值可以是任何引用数据类型的值,可以重复:键值对存放无序. Hash ...

  7. mybatis-自定义映射resultMap

    自定义映射resultMap resultMap处理字段和属性的映射关系 resultMap:设置自定义映射 属性: id:表示自定义映射的唯一标识,不能重复 type:查询的数据要映射的实体类的类型 ...

  8. 「浙江理工大学ACM入队200题系列」问题 J: 零基础学C/C++83——宁宁的奥数路

    本题是浙江理工大学ACM入队200题第八套中的J题 我们先来看一下这题的题面. 题面 题目描述 宁宁参加奥数班,他遇到的第一个问题是这样的:口口口+口口口=口口口,宁宁需要将1~9 九个数分别填进对应 ...

  9. C#设置picturebox滚动条来实现查看大图片

    要给PictureBox添加滚动条需要以下步骤:    (1)将picturebox放在panel上:   ( 2)将panel的AutoScroll设置为ture:    (3)将picturebo ...

  10. NOI2011真题:兔兔与蛋蛋游戏

    NOI2011真题:兔兔与蛋蛋游戏 题目描述 这些天,兔兔和蛋蛋喜欢上了一种新的棋类游戏. 这个游戏是在一个 n行 m 列的棋盘上进行的.游戏开始之前,棋盘上有一个格子是空的,其它的格子中都放置了一枚 ...