首页 技术 正文
技术 2022年11月11日
0 收藏 837 点赞 3,392 浏览 2256 个字

学习总结

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

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,492
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,907
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,740
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,493
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,132
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,295