9.1
#include <stdio.h>
double min(double,double);
int main(void)
{
double x,y;
while(scanf("%lf %lf",&x,&y)!=2)
{
printf("please,input two numbers.\n");
while(getchar()!='\n')
;
}
double smaller=min(x,y);
printf("%g is smaller between %g %g.\n",smaller,x,y);
return 0;
}
double min(double x,double y)
{
return x<y?x:y;
}
9.2
#include <stdio.h>
#define LINE 40
void chline(char,int,int);
int main(void)
{
char ch;
int i,j;
printf("please,input a character and two integers.the first number is smaller than the other.\n");
while(3!=scanf("%c %d %d",&ch,&i,&j))
{
printf("please,input a character and two integers.the first number is smaller than the other.\n");
while(getchar()!='\n')
;
}
chline(ch,i,j);
return 0;
}
void chline(char ch,int i,int j)
{
int k,l;
for(l=1;l<=LINE;l++)
{
for(k=0;k<i;k++);
for (;k<=j;k++)
putchar(ch);
printf("\n");
}
}
9.3
#include <stdio.h>
void charater(char,int,int);
int main(void)
{
char ch;
int i,j;
printf("please,input a characer and two intergers.\n");
while(scanf("%c %d %d",&ch,&i,&j)!=3)
{
printf("please,input a characer and two intergers.\n");
while(getchar()!='\n')
;
}
charater(ch,i,j);
return 0;
}
void charater(char ch,int i,int j)
{
int k,l;
for(l=1;l<=j;l++)
{
for(k=1;k<=i;k++)
putchar(ch);
printf("\n");
}
}
9.4
#include <stdio.h>
double average(double,double);
int main(void)
{
double x,y,value;
printf("please,input two numbers.\n");
while(scanf("%lf %lf",&x,&y)!=2)
{
printf("please,input two numbers.\n");
while(getchar()!='\n')
;
}
value=average(x,y);
printf("the average is %g",value);
return 0;
}
double average(double x,double y)
{
return 2*x*y/(x+y);
}
9.5
#include <stdio.h>
void larger_of(double*,double*);
int main(void)
{
double x,y;
printf("please,input two numbers.\n");
while(scanf("%lf %lf",&x,&y)!=2)
{
printf("please,input two numbers.\n");
while(getchar()!='\n')
;
}
larger_of(&x,&y);
printf("now x is %g ,and y is %g",x,y);
return 0;
}
void larger_of(double*x,double*y)
{
double temp=*x>*y?*x:*y;
*x=*y=temp;
}
9.6
#include <stdio.h>
#include <ctype.h>
int alphaornot(char);
int main(void)
{
int i;
char ch;
while(scanf(" %c",&ch)!=EOF)
{
i=alphaornot(ch);
if (i>0)printf("yes,%c is a letter,it's order is %d.\n",ch,i);
else printf("no ,%c it is not a letter.\n",ch);
}
return 0;
}
int alphaornot(char ch)
{
if (isalpha(ch))
return tolower(ch)-96;
else return -1;
}
9.7
#include <stdio.h>
double powerall(double,int);
double power(double,int);
int main(void)
{
int d;
double f,pow;
printf("please,input two numbers\n");
while(scanf("%lf %d",&f,&d)!=2)
{
printf("please,input two numbers\n");
while(getchar()!='\n')
;
}
pow=powerall(f,d);
printf("%g's%d power is %g.\n",f,d,pow);
return 0;
}
double powerall(double x,int y)
{
if (x!=0)
if(y<0) return 1/power(x,-y);
else return power(x,y);
else return 0;
}
double power(double x,int y)
{
int i;
double sum=1;
if(y==0)
return 1;
else
for(i=1;i<=y;i++)
sum*=x;
return sum;
}
9.8
#include <stdio.h>
double powerall(double,int);
double power(double,int);
int main(void)
{
int d;
double f,pow;
printf("please,input two numbers\n");
while(scanf("%lf %d",&f,&d)!=2)
{
printf("please,input two numbers\n");
while(getchar()!='\n')
;
}
pow=powerall(f,d);
printf("%g's%d power is %g.\n",f,d,pow);
return 0;
}
double powerall(double x,int y)
{
if (x!=0)
if(y<0) return 1/power(x,-y);
else return power(x,y);
else return 0;
}
double power(double x,int y)
{
if (y==1) return x;
else return x*power(x,y-1);
}
9.9
#include <stdio.h>
void to_base_n(unsigned long,unsigned long);
int main(void)
{
unsigned long number;
unsigned long rule;
printf("Enter two integer (q to quit):\n");
while (scanf("%lu %lu", &number,&rule) == 2)
{
printf("%lu equivalent: ",rule);
to_base_n(number,rule);
putchar('\n');
printf("Enter two integer (q to quit):\n");
}
printf("Done.\n");
return 0;
}
void to_base_n(unsigned long n,unsigned long i)
{
int r;
r = n % i;
if (n >= i)
to_base_n(n/i,i);
putchar('0' + r);
return;
}
9.10
#include <stdio.h>
#define size 50
int main(void)
{
int i,j,a[size];
printf("input a integer for Fibonacci(n). q to quit.\n");
while(scanf("%d",&i)==1)
{
if(i<=2&&i>=1)
{
printf("the Fibonacci(%d) is 1\n",i);
continue;
}
else if (i<=0)
printf("you input a wrong value.\n");
else
{
a[0]=1,a[1]=1;
for(j=2;j<=i-1;j++)
a[j]=a[j-1]+a[j-2];
printf("the Fibonacci(%d) is %d.\n",i,a[i-1]);
}
printf("input a integer for Fibonacci(n). q to quit.\n");
}
return 0;
}
分享到:
相关推荐
C Primer Plus 第五版第九章答案,自己编写可以成功运行
( C Primer Plus(第五版)中文版课后编程题全解,非常全,亲测可用
C Primer Plus(第五版)中文版.txt fhnfdjjy
c primer plus 第五版课后习题答案
c++ primer plus 第五版课后习题答案
C Primer Plus第6版编程练习答案.pdf
C Primer Plus第五版中文版是全球最经典的C语言教程,(包括PDF,书中源码,习题解答)。由于资格的原因,分4个RAR上传,都要下载。
C++PrimerPlus第五版习题参考答案
c入门必看的c primer plus ,其课后练习题也是很不错的。
C Primer Plus(第五版)中文版,学习C语言必备,讲的特别详细
c primer plus 第六版 中文版 源代码+勘误+习题答案,从官方处获得,因为官网需注册很麻烦,所以索性上传,与大家分享。 共三部分,针对第六版,含课后习题,源代码,书中勘误。
《C Primer Plus》第六版 第十一章编程练习答案,亲测编译通过
在这里下载了C Primer Plus(第五版)中文版可惜没有书签,就用OCR获取了书签生成了用 PdgCntEditor 1.07a 可以使用的格式共大家自行添加书签。不过原书是加密的不能编辑还有借助解密工具PDF Password Remover v3.0 。...
本书是c++ primer plus第五版的源代码,以及好多高手的编程心路沥程,不得不看!! 听君一席话胜读十年书!
C++Primer Plus(第6版)中文版编程练习答案--第四章.pdf
c++ primer plus 课后编程练习的完整答案 PDF文件.
《C++ Primer Plus第6版中文版》学习笔记(第十章) 红字内容是有疑问或者没把握的。 绿字部分是比较重要,或者经过确认的
通过学习《C Primer Plus(第五版)中文版》,你将奠定坚实的C编程基础。 与以前的版本一样,作者的目标仍旧是为读者提供一本入门性、条理清晰、见解深刻的C语言教程。作者把编程概念和C语言的细节很好地融合在一起...
C Primer Plus (第五版)中文版——第 8 章 编程练习参考程序
C Primer Plus (第五版) 课后编程练习答案 (完整) 文字版