关闭

c primer plus 第九章 答案

255人阅读 评论(0) 收藏 举报
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

猜你在找
【直播】机器学习&数据挖掘7周实训--韦玮
【套餐】系统集成项目管理工程师顺利通关--徐朋
【直播】3小时掌握Docker最佳实战-徐西宁
【套餐】机器学习系列套餐(算法+实战)--唐宇迪
【直播】计算机视觉原理及实战--屈教授
【套餐】微信订阅号+服务号Java版 v2.0--翟东平
【直播】机器学习之矩阵--黄博士
【套餐】微信订阅号+服务号Java版 v2.0--翟东平
【直播】机器学习之凸优化--马博士
【套餐】Javascript 设计模式实战--曾亮
查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:491次
    • 积分:12
    • 等级:
    • 排名:千里之外
    • 原创:1篇
    • 转载:0篇
    • 译文:0篇
    • 评论:0条
    文章存档
    阅读排行