部分代码_C primer plus 第三章 (代码部分)
3.1 platinum.c
/* platinum.c -- your weight in platinum */
#include<stdio.h>
int main(void)
{float weight; /* 你的体重 */float value; /* 相等重量的白金价值 */printf("Are you worth your weight in platinum?n");printf("Let's check it out.n");printf("Plese enter your weight in pounds: ");/* 捕获用户的输入 */scanf_s("%f", &weight);/* 假设白金价值的加个是每盎司$1700 *//* 14.5833 用于把英镑常衡盎司转换为金衡盎司 */value = 1700.0 * weight * 14.5833;printf("Your weight in platinum is worth $%.2f.n", value);printf("You are easily worth that! If platinum prices drops,n");printf("eat more to maintain your value.n");return 0;
}
3.3-1
/* toobing.c -- 超出系统的最大int值 */
#include<stdio.h>
int main(void)
{int i = 2147483647;unsigned int j = 4294967295;printf("%d %d %dn", i, i + 1, i + 2);printf("%u %u %un", j, j + 1, j + 2);return 0;
}
3.4 print.c
/* print2.c -- 更多printf()的特性 */
#include<stdio.h>
int main(void)
{unsigned int un = 3000000000; /* int为32位和short()为16位的系统 */short end = 200;long big = 65537;long long verybig = 12345678908642;printf("un = %u and not %dn", un, un);printf("end = %hd and %dn", end, end);printf("big = %ld and not %hdn", big, big);printf("verybig = %lld and not %ldn", verybig, verybig);return 0;
}
3.5 charcode.c
/* charcode.c - 显示字符的代码编号 */
#include<stdio.h>
int main(void)
{char ch;printf("Please enter a character.n");scanf_s("%c", &ch); /* 用户输入字符 */printf("The code for %c is %d.n", ch, ch);return 0;
}
3.7 showf_pt.c
/* showf_pt.c -- 以两种方式显示float类型的值 */
#include<stdio.h>
int main(void)
{float aboat = 32000.0;double abet = 2.14e9;long double dip = 5.32e-5;printf("%f can be written %en", aboat, aboat);// 下一行要求编译器支持C99或其中的相关特性printf("And it's %a in hexadecimal, pwoers of 2 notationn", aboat);printf("%f can be written %en", abet, abet);printf("%Lf can be written %Len", dip, dip);return 0;
}
3.8 typesize.c
/* typesize.c -- 打印类型大小 */
#include<stdio.h>
int main(void)
{/* c99为类型大小提供%zd转换说明 */printf("Type int has a size of %zd bytes.n", sizeof(int));printf("Type char has a size of %zd bytes.n", sizeof(char));printf("Type long has a size of %zd bytes.n", sizeof(long));printf("Type long long has a size of %zd bytes.n", sizeof(long long));printf("Type double has a size of %zd bytes.n", sizeof(double));printf("Type long double has a size of %zd bytes.n", sizeof(long double));return 0;
}
3.9 badcount.c
/* badcount.c -- 参数错误的情况 */
#include<stdio.h>
int main(void)
{int n = 4;int m = 5;float f = 7.0f;float g = 8.0f;printf("%dn", n, m); /* 参数太多 */printf("%d %d %dn", n); /* 参数太少 */printf("%d %dn", f, g); /* 值的类型不匹配 */return 0;
}
3.10 escape.c
/* escape.c -- 使用转义序列 */
#include<stdio.h>
int main(void)
{float salary;printf("aEnter your desired monthly salary:"); /* 1 */printf("$________bbbbbbbb"); /* 2 */scanf_s("%f", &salary);printf("nt$%.2f a month is $%.2f a year.", salary, salary * 12.0); /* 3 */printf("rGee!n"); /* 4 */return 0;
}
部分代码_C primer plus 第三章 (代码部分)相关推荐
- C Primer Plus第三章总结
C Primer Plus第三章总结 关于整数和浮点数 关于整数的常用的关键词有:char.int .long.longlong.unsigned-- 浮点数常用的关键词有:double.float ...
- 读书笔记之《重构》第三章—代码的坏味道
第三章 代码的坏味道 这一章告诉我们,什么样的代码需要去重构,该用什么方法.寻找代码的坏味道,就是从代码中找出特定的结构,这些结构指出重构的可能性.寻找这些结构,需要学会判断,判断一个类里面有多少实例 ...
- python基础代码事例-python基础第三章
第三章主要讲解Python的print语句的应用和赋值语句,代码块与缩进,条件语句,循环语句.这几种基础的语句 Python 条件语句 Python条件语句是通过一条或多条语句的执行结果(True或者 ...
- Android App 瘦身总结 第三章 代码混淆及优化
目录 一.代码混淆proguard 二.调整第三方库 三.环境差异依赖 四.代码习惯 五.插件化 六.总结 在前两章我们分别从图片资源和jni动态库这两个方面来分析apk瘦身的优化点 Android ...
- 《重构-改善既有代码的设计》第三章(上)
文章目录 前言 一.重复代码(Duplicated Code) 二.过长函数(Long Method) 三.过大的类(Large Class) 四.过长的参数列(Long Parameter List ...
- C Primer Plus 第三章 数据和C 阅读笔记
第3章 数据和C 3.1 示例程序 3.1.1 程序中的新元素 3.2 变量与常量数据 3.3 数据:数据类型关键字 3.4 C语言基本数据类型 3.4.1 int类型 3.4.2 其他整数类型 3. ...
- 《C++ primer》--第三章
习题3.2 什么是默认构造函数? 解答: 默认构造函数就是在没有显示提供初始化式时调用的构造函数.它由不带参数的构造函数,或者为所有形参提供默认实参的构造函数定义.如果定义某个类的变量时没有提供初始化 ...
- 《程序员代码面试指南》第三章 二叉树问题 二叉树节点间的最大距离问题
题目 二叉树节点间的最大距离问题 java代码 package com.lizhouwei.chapter3;/*** @Description:二叉树节点间的最大距离问题* @Author: liz ...
- 卜若的代码笔记-webgl系列-第三章:几何渲染Rendering Geometry
1 在webgl里面表述几何体最关键的两种数据类型: 顶点和索引(vertices and indices.) 1.1 顶点是什么? 顶点定义了3D对象的角点,每一个顶点由三个元素组成x,y,z. 在 ...
最新文章
- 新手探索NLP(九)——文本摘要
- Matlab画地球剖面图,分享用matlab显示地震记录的波形变面积图
- python分支结构使用if保留字吗_关于Python分支结构,以下选项中描述不正确的是...
- python三十三节_第三十三节,sys解释器相关模块
- CreateProcess 重定向CMD实现反弹shell
- iOS6.0以上版本,关于NSDateFormatter的问题
- 【观点】传统企业如何在数字化时代实现进化?
- 各种手机处理器排行榜_11月新机性能排行榜:荣耀V30第四,vivo S5上榜
- 【转】关于python中re模块split方法的使用
- 从闭包到 语法糖 装饰器
- 江小白包装设计原型_江小白的跨界营销,系列设计很“牛啤”!
- 系统管理员不可不知的三条黄金法则
- Cocos Creator 粒子编辑插件推荐
- 鸿蒙不支持PDF,华为鸿蒙 HarmonyOS IoT 应用设计文档(1).pdf
- 社交网络影响力最大化——贪心算法实现(Python实现)
- Linux7网卡绑定后mac一样,如何解决双网卡bond0绑定模式物理成员口的mac地址和bonding接口mac地址不一致......
- 《StereoDRNet: Dilated Residual StereoNet》
- PS 去除图片中的字
- 大天使之剑h5服务器临时维护,大天使之剑H5合服细节 战盟对决时间安排
- 流式保护器在文物建筑物内的电气防火应用