《c primer plus》编程练习回顾-第九章
2015-03-14 23:35
211 查看
1.
2.
3
4.
5.
6.
7.
8.
9.
#include<stdio.h> double min(double a, double b); int main(void) { double x, y; scanf("%lf%lf", &x, &y); printf("%lf", min(x, y)); return 0; } double min(double a, double b) { return a < b ? a : b; }
2.
#include<stdio.h> void chline(char ch, int i, int j); int main(void) { char ch; int a, b; scanf("%c%d%d", &ch, &a, &b); chline(ch, a, b); return 0; } void chline(char ch, int i, int j) { for (int k = 1; k < i; k++) printf(" "); for (; i <= j; i++) printf("%c", ch); }
3
#include<stdio.h> void fun(char ch, int a, int b); int main(void) { char ch; int x, y; scanf("%c%d%d", &ch, &x, &y); fun(ch, x, y); return 0; } void fun(char ch, int a, int b) { for (int i = 0; i < a; i++) { for (int i = 0; i < b; i++) printf("%c", ch); printf("\n"); } }
4.
#include<stdio.h> double fun(double a, double b); int main(void) { double x, y; scanf("%lf%lf", &x, &y); printf("%lf", fun(x, y)); return 0; } double fun(double a, double b) { double c; c = 1 / ((1 / a + 1 / b) / 2); return c; }
5.
#include<stdio.h> void larger_of(double *a, double *b); int main(void) { double x, y; scanf("%lf%lf", &x, &y); larger_of(&x, &y); printf("%lf %lf\n", x, y); return 0; } void larger_of(double *a, double *b) { *a = *b = *a > *b ? *a : *b; }
6.
#include<stdio.h> #include<ctype.h> int fun(char ch); int main(void) { char ch; scanf("%c", &ch); printf("%c\'s position is %d\n", ch, fun(ch)); return 0; } int fun(char ch) { int a; char ch1; if (isalpha(ch)) { printf("%c is a alpha.\n", ch); ch1 = toupper(ch); a = ch1 - 65 + 1; return a; } else return -1; }
7.
#include<stdio.h> #include<math.h> double power(double x, int y); int main(void) { double a; int b; while (scanf("%lf%d", &a, &b) == 2) { printf("%lf\n", power(a, b)); } return 0; } double power(double x, int y) { double c = 1; if (y > 0) { for (int i = 0; i < y; i++) c *= x; return c; } else if (y < 0) { for (int i = 0; i < -y; i++) c /= x; return c; } else if (x != 0) return 1; else return 1 / x; }
8.
*
9.
这里写代码片
相关文章推荐
- 《c primer plus》编程练习回顾-第五章
- c++.primer.plus第五版第九章编程练习答案
- 记录——《C Primer Plus (第五版)》第九章编程练习第四题
- 《c primer plus》编程练习回顾-第三章
- 记录——《C Primer Plus (第五版)》第九章编程练习第八题
- 记录——《C Primer Plus (第五版)》第九章编程练习第十题
- c++ primer plus(第6版)中文版 第九章编程练习答案
- C Primer Plus (第五版) 第九章 函数 编程练习
- 《c primer plus》编程练习回顾-第二章
- C++ primer plus(sixth edition) 编程练习答案(answers for programing exercises)第九章(chapter 9) 1-4
- C.Primer.Plus(第六版)第九章 编程练习
- 《c primer plus》编程练习回顾-第十章
- 《c primer plus》编程练习回顾-第八章
- C++ Primer Plus第六版 第九章 编程练习答案
- 《c primer plus》编程练习回顾-第七章
- 记录——《C Primer Plus (第五版)》第九章编程练习第二题
- C++ primer plus 第九章编程练习
- C Primer Plus 第九章 编程练习 1-9题
- 《c primer plus》编程练习回顾-第四章
- 《c primer plus》编程练习回顾-第十一章(上)