教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 文库大全 > 资格考试 >

第四版谭浩强c语言课后答案 完整版(2)

来源:网络收集 时间:2026-02-18
导读: else printf(max=%d\n,b); else if (ac) printf(max=%d\n,c); else printf(max=%d\n,a); return 0; }#include stdio.h int main() { int a,b,c,temp,max; printf(请输入三个整数:); scanf(%d,%d,%d,a,b,c); temp=(a

else

printf("max=%d\n",b);

else if (a<c)

printf("max=%d\n",c);

else

printf("max=%d\n",a);

return 0;

}#include <stdio.h>

int main()

{ int a,b,c,temp,max;

printf("请输入三个整数:");

scanf("%d,%d,%d",&a,&b,&c);

temp=(a>b)?a:b; /*将a和b中的大者存入temp中*/

max=(temp>c)?temp:c; /*将a和b中的大者与c比较,取最大者*/

printf("三个整数的最大数是%d\n",max);

return 0;

} #include <stdio.h>

#include <math.h>

谭浩强 c语言程序设计 第四版 完整版课后答案

#define M 1000

int main() {

int i,k;

printf("请输入一个小于%d的整数i:",M);

scanf("%d",&i);

while (i>M)

{printf("输入的数不符合要求,请重新输入一个小于%d的整数i:",M);

scanf("%d",&i); }

k=sqrt(i);

printf("%d的平方根的整数部分是:%d\n",i,k);

return 0; }

#include <stdio.h>

#include <math.h>

#define M 1000

int main() {

int i,k;

谭浩强 c语言程序设计 第四版 完整版课后答案

printf("请输入一个小于%d的整数i:",M);

scanf("%d",&i);

if (i>M)

{printf("输入的数不符合要求,请重新输入一个小于%d的整数i:",M);

scanf("%d",&i); }

k=sqrt(i);

printf("%d的平方根的整数部分是:%d\n",i,k);

return 0; }

#include <stdio.h>

int main()

{ int x,y;

printf("输入x:");

scanf("%d",&x);

if(x<1) /* x<1 */

{ y=x;

printf("x=%3d, y=x=%d\n" ,x,y);

}

else if(x<10) /* 1=<x<10 */

谭浩强 c语言程序设计 第四版 完整版课后答案

{ y=2*x-1;

printf("x=%d, y=2*x-1=%d\n",x,y);

}

else /* x>=10 */

{ y=3*x-11;

printf("x=%d, y=3*x-11=%d\n",x,y);

}

return 0;

}#include <stdio.h>

int main() {

int x,y;

printf("enter x:");

scanf("%d",&x);

y=-1;

if(x!=0)

if(x>0)

y=1;

else

y=0;

printf("x=%d,y=%d\n",x,y);

return 0;

谭浩强 c语言程序设计 第四版 完整版课后答案

}

#include <stdio.h>

int main() {

int x,y;

printf("please enter x:");

scanf("%d",&x);

y=0;

if(x>=0)

if(x>0) y=1;

else y=-1;

printf("x=%d,y=%d\n",x,y);

return 0; }

#include <stdio.h>

int main()

{ float score;

char grade;

printf("请输入学生成绩:");

scanf("%f",&score);

while (score>100||score<0)

谭浩强 c语言程序设计 第四版 完整版课后答案

{printf("\n 输入有误,请重输");

scanf("%f",&score);

}

switch((int)(score/10))

{case 10:

case 9: grade='A';break;

case 8: grade='B';break;

case 7: grade='C';break;

case 6: grade='D';break;

case 5:

case 4:

case 3:

case 2:

case 1:

case 0: grade='E';

}

printf("成绩是 %5.1f,相应的等级是%c\n ",score,grade);

return 0; }

#include <stdio.h>

#include <math.h>

int main()

谭浩强 c语言程序设计 第四版 完整版课后答案

int num,indiv,ten,hundred,thousand,ten_thousand,place; //分别代表个位,十位,百位,千位,万位和位数

printf("请输入一个整数(0-99999):");

scanf("%d",&num);

if (num>9999)

place=5;

else if (num>999)

place=4;

else if (num>99)

place=3;

else if (num>9)

place=2;

else place=1;

printf("位数:%d\n",place);

printf("每位数字为:");

ten_thousand=num/10000;

thousand=(int)(num-ten_thousand*10000)/1000;

hundred=(int)(num-ten_thousand*10000-thousand*1000)/100;

ten=(int)(num-ten_thousand*10000-thousand*1000-hundred*100)/10;

indiv=(int)(num-ten_thousand*10000-thousand*1000-hundred*100-ten*10);

switch(place)

{case 5:printf("%d,%d,%d,%d,%d",ten_thousand,thousand,hundred,ten,indiv);

谭浩强 c语言程序设计 第四版 完整版课后答案

printf("\n反序数字为:");

printf("%d%d%d%d%d\n",indiv,ten,hundred,thousand,ten_thousand);

break;

case 4:printf("%d,%d,%d,%d",thousand,hundred,ten,indiv);

printf("\n反序数字为:");

printf("%d%d%d%d\n",indiv,ten,hundred,thousand);

break;

case 3:printf("%d,%d,%d",hundred,ten,indiv);

printf("\n反序数字为:");

printf("%d%d%d\n",indiv,ten,hundred);

break;

case 2:printf("%d,%d",ten,indiv);

printf("\n反序数字为:");

printf("%d%d\n",indiv,ten);

break;

case 1:printf("%d",indiv);

printf("\n反序数字为:");

printf("%d\n",indiv);

break;

}

return 0;

}#include <stdio.h>

…… 此处隐藏:1202字,全部文档内容请下载后查看。喜欢就下载吧 ……
第四版谭浩强c语言课后答案 完整版(2).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wenku/107027.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)