记录下写的最后几题。

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. Android View底层到底是怎么绘制的

    Android绘制链图: 网上很多讲Android  view的绘制流程往往只讲到了Measure - Layout - Draw. 但是,这只是一个大体的流程,而我们需要探讨的是Android在我们 ...

  2. 对嵌入式开发C语言结构体的一点总结

    今天冬至居然不上班,公司的良心啊!这回有心情写博客和日志了,好了,废话不多说.直接看下文: 鉴于嵌入式开发过程中,C语言结构体的使用当然是必不可少.话说,基础什么的比你会更牛逼的算法更重要,基础不牢, ...

  3. Java进阶(二十)解疑答惑之何时字符串才算真正为空?

    解疑答惑之何时字符串才算真正为空? 在一次编码过程中,有一个现象一直困扰着自己,经过后台的不断调试,才发现原来有时候字符串的空非空.测试代码如下: // medname可为药品名称或药品ID Stri ...

  4. 【一天一道LeetCode】#29. Divide Two Integers

    一天一道LeetCode系列 (一)题目 Divide two integers without using multiplication, division and mod operator. If ...

  5. C#数据库连接操作大全

    一:数据库连接代码: SqlConnection objSqlConnection = new SqlConnection ("server = 127.0.0.1;uid = sa; pw ...

  6. SpriteBuilder中的粒子系统属性

    一个粒子发射器可以有2种模式,放射状和重力的(radial or gravity) 放射状模式允许你去使用发射器创建粒子旋涡状环绕在指定位置的效果. 当启用重力效果,你可以使得粒子在任何方向任意飞行, ...

  7. 百度地图android studio导入开发插件

    百度地图SDK v3.5.0开发包下载地址:http://lbsyun.baidu.com/sdk/download?selected=location 开发工具 Android开发工具很多,在这我们 ...

  8. Java-ServletConfig

    /** * * A servlet configuration object used by a servlet container * to pass information to a servle ...

  9. Netflix公布个性化和推荐系统架构

    Netflix的推荐和个性化功能向来精准,前不久,他们公布了自己在这方面的系统架构. 3月27日,Netflix的工程师Xavier Amatrain和Justin Basilico在官方博客发布文章 ...

  10. ra_interface_lines_all 接口表各字段说明

    note:Description and Usage of Fields in RA_INTERFACE_LINES Table [ID 1195997.1] 核心内容: Field Name and ...