学习总结

1、if…else…从语义上看就能出用途,跟其他语言没差多少,只需要记住,世界上最遥远的距离之一:我走if你却走else。

2、根据个人几年的编程经验,太多的if…else…嵌套会加大代码的可读性和维护难度。个人认为代码最好不要超过三层if…else…的嵌套,否则最好使用布尔值控制流程。

3、逻辑运算符优先级:!>&&>||

4、运行到continue语句将导致剩余的迭代部分被忽略,开始下一次迭代。continue仅用于循环,而break语句用于循环和switch中。

5、编程题(题1):

 #include <stdio.h>

 int main(){
int space=,newline=,other=;
char ch;
printf("please enter something:\n");
while((ch=getchar())!='#'){
if(ch=='\n'){
newline+=;
}else if(ch==' '){
space+=;
}else{
other+=;
}
}
printf("space is %d\n",space);
printf("newline is %d\n",newline);
printf("other is %d\n",other);
return ;
}

运行结果:

please enter something:

hello world!

hi nihao.

#ABC

space is 2

newline is 2

other is 19

6、编程题(题11):

 #include <stdio.h>
#define ARTICHOKE_UNIT_PRIC 1.25
#define BEET_UNIT_PRICE 0.65
#define CAROTA_UNIT_PRICE 0.89
#define DISCOUNT 0.05
#define T_0_5 3.50
#define T_5_20 10.00
#define T_20_ 0.1 int main(){
double a,b,c,ap,bp,cp,ac,bc,cc,sc,dc,tc;
ap=ARTICHOKE_UNIT_PRIC;
bp=BEET_UNIT_PRICE;
cp=CAROTA_UNIT_PRICE;
printf("how many artichoke you want(pound):");
scanf("%lf",&a);
if(a==)return ; printf("how many beet you want(pound):");
scanf("%lf",&b);
if(b==)return ; printf("how many carota you want(pound):");
scanf("%lf",&c);
if(c==)return ; printf("\n------UNIT PRICE------\n");
printf("artichoke's unit price is $%.2f(one pound) \n",ap);
printf("beet's unit price is $%.2f(one pound)\n",bp);
printf("carota'unit price is $%.2f(one pound)\n",cp); printf("\n------ORDER------\n");
printf("artichoke:%.2fpound\n",a);
printf("beet:%.2fpound\n",b);
printf("carota:%.2fpound\n",c); printf("\nartichoke is $%.2f",a*ap);
printf("\nbeet is $%.2f",b*bp);
printf("\ncarota is $%.2f\n",c*cp);
sc=a*ap+b*bp+c*cp;
printf("\ntotal cost is $%.2f",sc);
dc=sc>?sc*DISCOUNT:;
printf("\ndiscount is $%.2f",dc); printf("\ntotal weight is %.2f",a+b+c);
if(<(a+b+c)<=){
tc=T_0_5;
}
if(<(a+b+c) && (a+b+c)<=){
tc=T_5_20;
}
if((a+b+c)>){
tc=+(a+b+c)*0.1;
}
printf("\nttransport cost is $%.2f",tc);
printf("\norder cost is $%.2f\n",sc-dc+tc); return ;
}

运行结果:

how many artichoke you want(pound):123

how many beet you want(pound):234

how many carota you want(pound):343

------UNIT PRICE------

artichoke's unit price is $1.25(one pound)

beet's unit price is $0.65(one pound)

carota'unit price is $0.89(one pound)

------ORDER------

artichoke:123.00pound

beet:234.00pound

carota:343.00pound

artichoke is $153.75

beet is $152.10

carota is $305.27

total cost is $611.12

discount is $30.56

total weight is 700.00

ttransport cost is $78.00

order cost is $658.56

【C语言学习】《C Primer Plus》第7章 C控制语句:分支与跳转的更多相关文章

  1. C Primer Plus 第7章 C控制语句:分支和跳转 编程练习

    作业练习 1. #include <stdio.h> int main(void) { char ch; int spare, other, n; //空格,其他字符,换行 spare = ...

  2. C Primer Plus 第6章 C控制语句:循环 编程练习

    记录下写的最后几题. 14. #include <stdio.h> int main() { double value[8]; double value2[8]; int index; f ...

  3. Go语言学习笔记四: 运算符

    Go语言学习笔记四: 运算符 这章知识好无聊呀,本来想跨过去,但没准有初学者要学,还是写写吧. 运算符种类 与你预期的一样,Go的特点就是啥都有,爱用哪个用哪个,所以市面上的运算符基本都有. 算术运算 ...

  4. C语言学习书籍推荐《C Primer Plus(中文版)(第5版)》下载

    普拉塔 (Prata S.) (作者), 云巅工作室 (译者) <C Primer Plus(中文版)(第5版)>共17章,介绍了C语言的基础知识,包括数据类型.格式化输入输出.运算符.表 ...

  5. 【C语言学习】《C Primer Plus》第1章 概览

    学习总结 1.C语言于1972年由贝尔实验室的Dennis Ritchie在与Ken Thompson一起设计UNIX操作系统的时候开发的.的的设计构想来源于Ken Thompson的B语言.Anyw ...

  6. linux 下C语言学习路线

    UNIX/Linux下C语言的学习路线.一.工具篇“公欲善其事,必先利其器”.编程是一门实践性很强的工作,在你以后的学习或工作中,你将常常会与以下工具打交道, 下面列出学习C语言编程常常用到的软件和工 ...

  7. 郝斌老师C语言学习笔记(一)

    在给变量分配内存时,很可能这段内存存在以前其他程序使用留下的值.当使用VC编译器,若编译器发现没有给变量赋值而使用,就会返回一个以“85”开头的很大的数字(此时该段内存中为一个垃圾数,为了避免出现较常 ...

  8. Unix和Linux下C语言学习指南

    转自:http://www.linuxdiyf.com/viewarticle.php?id=174074 Unix和Linux下C语言学习指南 引言 尽管 C 语言问世已近 30 年,但它的魅力仍未 ...

  9. C语言学习 第八次作业总结

    本次作业其实没有新的内容,主要就是复习上一次的一维数组的相关内容.冯老师布置了5道题目,其中涉及到一些比较简单的排序或者是查找的方法.因为数据很少,所以直接使用for循环遍历就可以了. 关于本次作业, ...

  10. C语言学习 第七次作业总结

    C语言学习 第七次作业总结 数组可以分为数组和多下标数组(在传统的国内C语言书本中,将其称为二/多维数组). 数组名称 在之前的课程中,大家应该都有印象,对于int a这样的定义,会为变量 a 声明一 ...

随机推荐

  1. Python list列表的排序

    当我们从数据库中获取一写数据后,一般对于列表的排序是经常会遇到的问题,今天总结一下python对于列表list排序的常用方法: 第一种:内建函数sort() 这个应该是我们使用最多的也是最简单的排序函 ...

  2. [python](爬虫)如何使用正确的姿势欣赏知乎的“长得好看是怎样一种体验呢?”问答中的相片

    从在知乎关注了几个大神,我发现我知乎的主页画风突变.经常会出现 ***长得好看是怎样一种体验呢? 不用***,却长得好看是一种怎样的体验? 什么样***作为头像? ... 诸如此类的问答.点进去之后发 ...

  3. ssh整合,导入structs包后报错 getAnnotation(AnnotatedElement ae,Class<T> annotatetype)找不到

    今天在整合ssh(spring-framework-3.2.5.RELEASE-dist+struts-2.3.15.3-all+hibernate-release-4.2.6.Final)环境的时候 ...

  4. hibernate配置文件中的schema="dbo"在MySQL数据库不可用

    把项目的数据库由SQL Server更改为MySQL之后,发现hibernate报错. 问题在于schema="dbo",使用SQL Sever数据库时正常,使用MySQL数据库需 ...

  5. [WPF]Slider控件常用方法

    WPF的Slider控件继承自RangeBase类型,同继承自RangeBase的控件还有ProgressBar和ScrollBar,这类控件都是在一定数值范围内表示一个值的用途. 首先注意而Rang ...

  6. Some About Spring

    什么是Spring:Spring是一个从实际开发中抽取出来的框架,它对代码中需要重复解决的步骤抽象成为了一个框架.留给开发者的仅仅是与特定应用相关的部分,大大提高了企业应用的开发效率.例外.Sprin ...

  7. VS与ultraedit 正则表达式替换

    ASP中把request("{param}")调用替换为requestX("{param}") VS 表达式替换(?<a>request\(&quo ...

  8. 在Linux上安装最新版java的JDK

    之前写过一篇关于MC建服的文章(http://www.cnblogs.com/apollospotatolikett/p/6149042.html),文章中使用的JDK不是最新的版本,当时没有细说如何 ...

  9. configure: error: no acceptable C compiler found in $PAT 的解决方案

    configure: error: no acceptable C compiler found in $PATH See `config.log' for more details.你的机器里没有安 ...

  10. hadoop多次搭建后,完整总结(累死宝宝了,搭建了十多遍了)

    1.安装JDK1.1上传运用软件FileZilla,将windows上的jdk压缩包放到linux的root目录下 1.2解压jdk #创建文件夹 mkdir /usr/java(不要挂在在" ...