记录下写的最后几题。

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. Leetcode_169_Majority Element

    本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/42247887 Given an array of size ...

  2. Cocos2D中相关问题提问的几个论坛

    如果和SpriteBuilder相关可以到: http://forum.spritebuilder.com 提问. 如果是Cocos2D的问题,则可以到以下论坛询问: http://forum.coc ...

  3. Leetcode_48_Rotate Image

    本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/44216867 You are given an n x n ...

  4. 如何调整DOS窗口的宽高

    运行->cmd->dos窗口上沿点右键->默认值所选字体字体: 新宋体大小: 13窗口大小宽度: 100高度: 40屏幕缓冲区大小宽度: 100高度: 300 在这里还可以设置依他常 ...

  5. Developing User Interfaces

      Developing a User Interface with ADF Faces Purpose This tutorial covers developing the user interf ...

  6. android 自定义相机

    老规矩,先上一下项目地址:GitHub:https://github.com/xiangzhihong/CameraDemo 方式: 调用Camera API 自定义相机 调用系统相机 由于需求不同, ...

  7. 图像的基本运算——scale, rotation, translation

    图像是视觉信息的直接反应,图像呈现出各种各样的特效都是通过图像的基本运算来完成的.图像最基本的运算有三种,分别是scale,rotation 和translation,叫做尺度,旋转和平移.很多图像的 ...

  8. HBase Region级别二级索引

    我们会经常谈及二级索引,这是对全表数据进行另外一种方式的组织存储,是针对table级别的.如果要为HBase上的表实现一个强一致性的二级索引,那么就无法逃避分布式事务,而这一直是用户最期待的功能. 而 ...

  9. 安卓系统底层C语言算法之测试参数是几个long型的算法

    #include <stdio.h> #define BITS_PER_LONG (sizeof(unsigned long) * 8) //求一个数x是几个long的长度 #define ...

  10. Jmeter(二十四)_服务器性能监控

    下载插件 1.访问网址http://jmeter-plugins.org/downloads/all/,下载三个文件.其中JMeterPlugins-Standard和JMeterPlugins-Ex ...