C primer plus第5章(运算符、表达式和语句)习题
来源:互联网 发布:专业的热分析软件 编辑:程序博客网 时间:2024/06/05 05:53
3.
#include <stdio.h>int main (void){ int i = 1; float n; printf("Watch out! Here come a bunch of fractions!\n"); while(i++ < 30) { n = 1.0/i;//将1改为1.0,当2个数都是整数时,第一次结果为1,当I增大时结果会一直为0,改为1.0(浮点型)则会有不同结果 printf("%f\n",n); } printf("That`s all,folks!\r"); return 0;}
4.
#include <stdio.h>#define FORMAT "%s! C is cool!\n"int main (void){ int num = 10; printf(FORMAT, FORMAT); printf("%d\n", ++num); printf("%d\n", num++); printf("%d\n", num--); printf("%d\n", num); return 0;}结果
%s! C is cool!
! C is cool!
11
11
12
11
6.
#include <stdio.h>int main (void){ char c1,c2; int diff; float num; c1 = 'S'; c2 = 'O'; diff = c1 - c2; num = diff; printf("%c%c%c: %d %3.2f\n", c1, c2,c1,diff,num); return 0;}
打印结果
SOS: 4 4.00
7.
#include <stdio.h>#define TEN 10int main (void){ int n = 0; while(n++ < TEN) printf("%5d",n); printf("\n"); return 0;}
8.
#include <stdio.h>int main (void){ char c = 'a'; while(c <= 'g') printf("%5c",c++); printf("\n"); return 0;}
9.
a.
1 2
b.
101
102
103
103
c.
stuvw
编程练习
1.
#include <stdio.h>int main (void){ const int MAX = 60; int num; while(num > 0) { scanf("%d",&num); } return 0;}
#include <stdio.h>int main (void){ int pl = 10; int num; printf("请输入数字\n"); scanf("%d",&num); while(pl >= 0) { printf("%d\n",num+pl); pl--; } return 0;}
3.
#include <stdio.h>int main (void){ const int PW = 7; int days; printf("请输入天数\n"); scanf("%d",&days); printf("%d周%d天",days/PW,days%PW); return 0;}
4.
#include <stdio.h>int main (void){ const float I_T_M = 2.54; const float M_T_I = 0.3937; float cm; while(cm > 0) { printf("请输入厘米长度\n"); scanf("%f",&cm); printf("%.2fcm\n%.2finch\n",cm,cm*I_T_M); } return 0;}
5.
#include <stdio.h>int main (void){ int count,sum,days; count = 0; sum = 0; scanf("%d",&days); while(count++ < days) sum = sum + count; printf("sum = %d\n", sum); return 0;}
6.
#include <stdio.h>int main (void){ int count,sum,days; count = 0; sum = 0; scanf("%d",&days); while(count++ < days) sum = sum + count * count; printf("sum = %d\n", sum); return 0;}
7.
#include <stdio.h>int main (void){ float num; scanf("%f",&num); printf("%f", num * num * num); return 0;}
8.
#include <stdio.h>//用到atof函数需要此包#include <stdlib.h>int main (void){ char fahrenheit[40]; double params; int n; while(1) { printf("请输入华氏温度\n"); scanf("%s",fahrenheit); n = strlen(fahrenheit); int i = 0; for(i=0; i<n; i++) { if((fahrenheit[i] < '0' || fahrenheit[i] > '9') && fahrenheit[i] != '.') { return 0; } } temperatures(atof(fahrenheit)); } return 0;}void temperatures(double fahrenheit){ const float C1 = 1.8; const float C2 = 32.0; const float K = 273.16; double celsius,kelvin; celsius = C1 * fahrenheit + C2; kelvin = celsius * K; printf("摄氏%f度\n",celsius); printf("绝对温度%f度\n",kelvin);}
- C primer plus第5章(运算符、表达式和语句)习题
- C Primer Plus 第五章:运算符、表达式和语句
- C primer plus 5 ch5 运算符、表达式和语句
- c primer plus第5章总结:运算符、表达式、语句
- C primer plus第7章(C控制语句:分支和跳转)习题
- C Primer Plus学习笔记----第五章运算符、表达式和语句
- C Primier Plus 第5章 运算符、表达式和语句
- C primer plus第6章(c控制语句:循环)习题
- c primer plus第14章习题
- c++primer plus 第12章习题
- C primer plus第1章(概览)习题
- C primer plus第9章(函数)习题
- C primer plus第10章(指针)习题
- C primer plus第3章(数据和C)习题
- C primer plus第11章(字符串和字符函数)习题(10选择排序)
- C primer plus第4章(字符串和格式化输入/输出)习题
- C primer plus第8章(字符输入/输出和输入确认)习题
- C primer plus第12章(存储类、链接和内存管理)习题
- photoshop中怎么绘制虚线
- JAVA面向对象C
- wget 用法详解
- 开IT行业之先河,蓝汛获国家技术发明奖有何玄机?
- 2003年专业考试真题(混凝土部分)
- C primer plus第5章(运算符、表达式和语句)习题
- ltp 交叉编译 出现error 解决
- 趣谈JAVA常用的设计模式
- cache:缓存在asp.net中如何管理?服务器端缓存?Session, Application, Cache objectscache ,客户端缓存?Cookies,ViewState (转)
- vb学习之菜鸟方案
- Android入门:使用Android GPS实现简单的定位
- Qt中导出.txt, .xls, .xlsx, .pdf文件小结
- C#例子程序
- c#例子程序