记录下写的最后几题。

14.
#include <stdio.h> int main() {
double value[8];
double value2[8];
int index;
for (index = 0; index < 8; ++index) { //输入值。
printf("value #%d:", index + 1);
scanf("%lf", &value[index]);
} for (index = 0; index < 8; index++) {
printf("%10.2lf", value[index]);
}
printf("\n"); value2[0] = value[0];
for (index = 1; index < 8; ++index) {
value2[index] = value2[index - 1] + value[index];
}
for (index = 0; index < 8; index++) {
printf("%10.2lf", value2[index]);
}
return 0;
}
15.
#include <stdio.h> int main() {
char symbol[255], ch;
int i = 0; do {
scanf("%c", &ch);
symbol[i++] = ch;
} while (ch != '\n'); while (i >= 0) {
printf("%c", symbol[i - 2]);
// -2是因为减去\n和最后多出来的一个没用的i,大概就是这个意思吧。
i--;
}
return 0;
}
16.
#include <stdio.h> #define PRINCIPAL 100.0
#define RATE_DAPHNE 0.1
#define RATE_DEIRDRE 0.05 // 给出本金,利率。
int main() {
double Daphne = PRINCIPAL;
double Deirdre = PRINCIPAL;
int years = 0;
while (Daphne >= Deirdre) {
Daphne = Daphne + RATE_DAPHNE * PRINCIPAL;
Deirdre = Deirdre + Deirdre * RATE_DEIRDRE;
years++;
}
printf("Daphone:$%.2lf \nDeirdre:$%.2lf \n", Daphne, Deirdre);
printf("Investment values after %d years.", years);
return 0;
}
17.
#include <stdio.h> #define RATE 0.08 // 给出利率。
int main() {
double principal = 100.0;
int years = 0;
while (principal > 0) {
principal = principal + principal * RATE - 10;
years++;
}
printf("It takes %d years to complete.", years);
return 0;
}
18.
#include <stdio.h> #define DUNBARS_NUMBER 150 int main() {
int friend = 5;
int value = 1;
int week = 1;
while (DUNBARS_NUMBER > friend) {
friend = (friend - value) * 2;
value++;
printf("Rabnud have %3d friends on the %2d of the week. \n",
friend, week);
week++;
}
return 0;
}

C Primer Plus 第6章 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 第3章 数据和C 编程练习

    1. /* 整数上溢 */ #include <stdio.h> int main(void) { ; unsigned ; /* 无符号整数j像一个汽车里程指示表(形容的太好了,可参考& ...

  3. C Primer Plus 第10章 数组和指针 编程练习

    这章感觉好难啊,放个别人的总结. // 多维数组和指针 #include <stdio.h> int main(void) { int zippo[4][2] = {{2, 4}, {6, ...

  4. C Primer Plus_第9章_函数_编程练习

    1.题略 /*返回较小值,设计驱动程序测试该函数*/ #include <stdio.h> double min (double a, double b); int main (void) ...

  5. C Primer Plus_第6章_循环_编程练习

    1.题略 #include int main(void) { int i; char ch[26]; for (i = 97; i <= (97+25); i++) { ch[i-97] = i ...

  6. C Primer Plus_第5章_运算符、表达式和语句_编程练习

    Practice 1. 输入分钟输出对应的小时和分钟. #include #define MIN_PER_H 60 int main(void) { int mins, hours, minutes; ...

  7. C Primer Plus_第四章_字符串和格式化输入输出_编程练习

    Practice 1.输入名字和姓氏,以"名字,姓氏"的格式输出打印. #include int main(void) { char name[20]; char family[2 ...

  8. 零基础学Python--------第3章 流程控制语句

    第3章 流程控制语句 3.1程序的结构 计算机在解决某个具体问题时,主要有3种情况,分别是顺序执行所有的语句.选择执行部分语句和循环执行部分语句.程序设计中的3种基本结构为顺序结构.选择结构和循环结构 ...

  9. Python实验报告——第3章 流程控制语句

    实验报告 [实验目的] 1.掌握python中流程控制语句的使用,并能够应用到实际开发中. [实验条件] 1.PC机或者远程编程环境 [实验内容] 1.完成第三章流程控制语句实例01-09,实战一到实 ...

随机推荐

  1. platform_driver_probe与platform_driver_register的区别

    Platform Device and Drivers  从<linux/platform_device.h>我们可以了解Platform bus上面的驱动模型接口:platform_de ...

  2. centos 系统时间的同步

    1.当你的网站架构涉及到多台服务器的时候,服务器之间的时间必须得同步,这样就涉及到了程序的时间的准确性问题,特别是跟时间相关的操作和系统本身的定时任务. 2.时间同步工具:ntpdate,安装方式:y ...

  3. Unity Singleton 单例类(Unity3D开发之二十)

    猴子原创,欢迎转载.转载请注明: 转载自Cocos2Der-CSDN,谢谢! 原文地址: http://blog.csdn.net/cocos2der/article/details/47335197 ...

  4. 苹果新的编程语言 Swift 语言进阶(十)--类的继承

    一.类的继承 类能够从其它类继承方法.属性以及其它特性,当一个类从另外的类继承时,继承的类称为子类,它继承的类称为超类.在Swift中,继承是类区别与其它类型(结构.枚举)的基础行为. 1.1 .类的 ...

  5. mybati源码之ReuseExecutor

    /** * @author Clinton Begin */ public class ReuseExecutor extends BaseExecutor { private final Map&l ...

  6. Android studio 项目(Project)依赖(非Module)

    Android studio 项目(Project)依赖(非Module) 0. 前言 对于Module 级别的依赖大家都知道,今天说下Android Studio下的项目依赖. 场景: A Proj ...

  7. 开发composer包,打通github和packagist,并自动更新

    1. 首先需要本地安装好composer,并配置好环境变量,在命令行输入composer,显示以下信息就表示正常安装 2. 在github对应项目的根目录下进行初始化composer 初始化完成后,就 ...

  8. ASP.NET Provider模式应用之SqlMembershipProvider类的剖析

    太多了,先给个流程图吧 Provider模式就是GOF中的两种设计模式的应用:策略模式和工厂模式,在程序中使用好这个模型能够解除模块与模块之间的耦合甚至是DIP,同时,不管是ASP.NET MVC还是 ...

  9. Kubernetes如何支持有状态服务的部署?

    作者:Jack47 转载请保留作者和原文出处 PS:如果喜欢我写的文章,欢迎关注我的微信公众账号程序员杰克,两边的文章会同步,也可以添加我的RSS订阅源. Kubernetes对无状态服务有完善的支持 ...

  10. jfinal的回滚

    有两种方法 1. @Before(Tx.class) public void test() throws Exception { } 优点:简单,不需要去处理每个异常,直接抛出异常: 缺点:不能详细的 ...