c primer plus 第九章 答案

9.1
#include <stdio.h>


double min (double x, double y);


int main(void)
{
double x,y;


printf("Please enter two numbers:\n");


while (scanf("%f %f",&x,&y)==2)
{
printf("The smaller number is %.2f.\n",min(x,y));
printf("Please enter next two numbers(q two exit):\n");


}
printf("BYE!!!\n");
return 0;
}


double min (double x, double y)
{
return x<y?x:y;
}




9.3
#include <stdio.h>


void chline ( char ch, int i, int j);


int main(void)


{
int i=0;
int j=0;
char ch;


printf("please enter the char you want to print: ");
ch=getchar();
printf("please enter i,j:");
scanf("%d %d",&i,&j);
chline(ch,i,j);






return 0;
}


void chline ( char ch, int i, int j)
{
for (int col1=0;col1<i;col1++)


{


for (int col2=0;col2<j;col2++)
putchar(ch);

putchar('\n');


}


}
9.4
#include <stdio.h>


double reciprocal ( double a, double b);


int main(void)
{
int x,y;
printf("Please enter two numbers:\n");
while(scanf("%d %d",&x,&y)==2)
{
printf("Harmonic mean:%lf .\n",reciprocal(x,y));
printf("Please enter next two numbers:\n");
}
printf("BYE!!!!");
return 0;
}


double reciprocal ( double a, double b)
{
double rec;
a=1/a;
b=1/b;
rec=1/((a+b)/2);
return rec;
}
9.5
#include <stdio.h>


double large_of (double a, double b );


int main(void)
{
double x,y;
printf("Please enter two numbers:\n");
while(scanf("%lf %lf",&x,&y)==2)
{
printf("Now x=y=%lf.\n",large_of(x,y));
printf("Please enter next two numbers:\n");
}
printf("BYE!!!!");
return 0;
}


double large_of ( double a, double b)
{
return a>b?a:b;


}
9.6
#include <stdio.h>


int  main(void)
{
   int chars;
   printf ("Please enter some words:\n"); 
   
   while ((chars=getchar())!=EOF)
   {
       if(chars>='a'&&chars<='z') 
  printf("You enter the '%c',It is the position of %d .\n",chars,chars-'a'+1);
       else if(chars>='A'&&chars<='Z') 
  printf("You enter the '%c',It is the position of %d .\n",chars,chars-'A'+1);
       else printf("You enter the character %c ,but it is not a letter .\n",chars);


   }
}






 







  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值