C Primer Plus 第九章 编程练习 1-9题
2017-03-09 20:02
232 查看
第一题
第二题
第三题
第四题
第五题
第六题
第七题
第八题
第九题
#include<stdio.h> double Min(double x , double y); int main(void) { double X; double Y; printf("Please Input First Number:\n"); scanf("%lf",&X); getchar(); printf("Please Input First Number:\n"); scanf("%lf",&Y); getchar(); printf("Min Number Is %.2lf.\n",Min(X,Y)); return 0; } double Min(double x , double y) { return (x<y)?x:y; }
第二题
#include<stdio.h> const char Ch = '*'; const int column = 10; const int row = 10; void chline(char ch , int x , int y); int main(void) { char Letters; int COL; int ROW; printf("PLease Input Any Charactor:\n"); scanf("%c",&Letters); getchar(); printf("Which Row Is You Want To Display On?\n"); scanf("%d",&ROW); getchar(); printf("Which Column Is You Want To Display On?\n"); scanf("%d",&COL); getchar(); chline(Letters,ROW,COL); return 0; } void chline(char ch , int x , int y) { for(int i = 1 ; i <= row ; ++i) { for(int j = 1 ; j <= column ; ++j) { if(i == x && j == y) printf("%c",ch); else printf("%c",Ch); } printf("\n"); } }
第三题
#include<stdio.h> void showChar(char ch , int x , int y); int main(void) { char Letters; int COL; int ROW; printf("PLease Input Any Charactor:\n"); scanf("%c",&Letters); getchar(); printf("How Many Row Is You Want To Display ?\n"); scanf("%d",&ROW); getchar(); printf("How Many Column Is You Want To Display On?\n"); scanf("%d",&COL); getchar(); showChar(Letters,ROW,COL); return 0; } void showChar(char ch , int x , int y) { for(int i = 1 ; i <= x ; ++i) { for(int j = 1 ; j <= y ; ++j) printf("%c",ch); printf("\n"); } }
第四题
#include<stdio.h> void Counts(double x , double y); int main(void) { double X; double Y; printf("Please Input First Number:\n"); scanf("%lf",&X); getchar(); printf("Please Input Second Number:\n"); scanf("%lf",&Y); getchar(); Counts(X,Y); return 0; } void Counts(double x , double y) { printf("Result is %.2lf\n",1/((1/x+1/y)/2)); }
第五题
#include<stdio.h> void larger_of(double* x ,double* y); int main(void) { double X; double Y; printf("PLease Input First Number:\n"); scanf("%lf",&X); getchar(); printf("PLease Input Second Number:\n"); scanf("%lf",&Y); getchar(); larger_of(&X,&Y); printf("%.2lf %.2lf",X,Y); return 0; } void larger_of(double* x ,double* y) { (*x > *y)?(*y = *x):(*x = *y); }
第六题
#include<stdio.h> #include<ctype.h> int checkLetter(char ch); int main(void) { char Letters; while((Letters = getchar()) != '\n') //'\n' replace EOF printf("%d ",checkLetter(Letters)); return 0; } int checkLetter(char ch) { if(isalpha(ch)) { if(islower(ch)) return (ch-96); if(isupper(ch)) return (ch-64); } return -1; }
第七题
#include<stdio.h> #include<stdbool.h> double myPow(double p ,int n); int main(void) { double X; int Y; while(true) { printf("Please Input Any Double To Test:\n"); if(!scanf("%lf",&X)) break; getchar(); printf("Please Input Another Integer To Test:\n"); if(!scanf("%d",&Y)) break; getchar(); printf("%.2lf POW %d Is %.2lf.\n",X,Y,myPow(X,Y)); } printf("Done!"); return 0; } double myPow(double p ,int n) { double ps = 1.0; if(p == 0) ps = 0; else { if(n > 0) { for(int i = 0 ; i < n ; ++i) ps *= p; } if(n < 0) ps = 1/ps; } return ps; }
第八题
#include<stdio.h> #include<stdbool.h> double myPow(double p ,int n); int main(void) { double X; int Y; while(true) { printf("Please Input Any Double To Test:\n"); if(!scanf("%lf",&X)) break; getchar(); printf("Please Input Another Integer To Test:\n"); if(!scanf("%d",&Y)) break; getchar(); printf("%.2lf POW %d Is %.2lf.\n",X,Y,myPow(X,Y)); } printf("Done!"); return 0; } double myPow(double p ,int n) { double POW = 1; if(n > 0) { --n; POW = p * myPow(p,n); } else if(n < 0) { ++n; POW = p * myPow(p,n); } return POW; }
第九题
#include<stdio.h> #include<stdbool.h> void to_base_n(unsigned long n , int types); int main(void) { unsigned long Number; int Type; bool on_off = true; printf("Please Input Any Integer To Test:\n"); int switch_1 = scanf("%lu",&Number); printf("Please Input Types(Integer 2 To 10):\n"); int switch_2 = scanf("%d",&Type); while(on_off) { if(switch_1 != 1 || switch_2 != 1 || Type > 10 || Type < 2) { on_off = false; continue; } to_base_ 9db2 n(Number,Type); printf("\n"); printf("Please Input Any Integer To Test:\n"); switch_1 = scanf("%lu",&Number); printf("Please Input Types(Integer 2 To 10):\n"); switch_2 = scanf("%d",&Type); } printf("Done!"); return 0; } void to_base_n(unsigned long n , int types) { int r; r = n%types; if(n >= types) to_base_n(n/types,types); putchar('0'+r); }
相关文章推荐
- c++.primer.plus第五版第九章编程练习答案
- 【学习C++】C++ Primer Plus (第六版)第九章编程练习1-4
- C++ Primer Plus第五版 第九章 编程练习答案
- C primer plus(第五版)编程练习第九章
- c++ primer plus(第6版)中文版 第九章编程练习答案
- 记录——《C Primer Plus (第五版)》第九章编程练习第十题
- 《c primer plus》编程练习回顾-第九章
- C++ primer plus 第九章编程练习
- 记录——《C Primer Plus (第五版)》第九章编程练习第二题
- 记录——《C Primer Plus (第五版)》第九章编程练习第一题
- c++ Primer Plus(第六版)第九章编程练习之路
- 记录——《C Primer Plus (第五版)》第九章编程练习第四题
- C ++ Primer Plus 第六版 第九章编程练习答案
- C.Primer.Plus(第六版)第九章 编程练习
- 记录——《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 13章编程练习7问题
- 编程菜鸟的日记-初学尝试编程-C++ Primer Plus 第4章编程练习4