c语言现代方法第二版第四章答案,C语言程序设计现代方法第四章课后习题

第一题

#include #include)

int main(void)

{

int a;

printf(“Enter a two-digit number:”);

scanf_s("%d", &a);

printf(“THE : %d%d”,a%10,a/10);

system(“pause”);

return 0;

}

第二题

#include #include)

int main(void)

{

int a;

printf(“Enter a two-digit number:”);

scanf_s("%d", &a);

printf(“THE : %d%d%d”,a%10,(a/10)%10,(a/10)/10);

system(“pause”);

return 0;

}

第三题

#include #include)

int main(void)

{

int a,b,c;

printf(“Enter a two-digit number:”);

scanf_s("%1d%1d%1d",&a,&b,&c);//通过限定位宽来实现不按回车输入三个数

printf(“THE reversal: %1d%1d%1d”,c,b,a);

system(“pause”);

return 0;

}

第四题

#include #include)

int main(void)

{

int a;

printf(“Enter a number between 0 and 32767:”);

scanf_s("%d",&a);

printf(“in octal,your number is: %o”,a);

system(“pause”);

//或者:

//int num10, num8;

//printf("enter a number between 0 and 32767: ");

//scanf("%d", &num10);

//int a, b, c, e, d;

//a = num10 % 8;

//b = (num10 / 8) % 8;

//c = (num10 / 8 / 8) % 8;

//d = (num10 / 8 / 8 / 8) % 8;

//e = (num10 / 8 / 8 / 8 / 8) % 8;

//printf("in octal, your number is: %d%d%d%d%d", e, d, c, b, a);

return 0;

}

第五题

#include #include)

int main(void)

{

int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11,b,bb,c;

printf(“Enter the first 11digits of a UPC:”);

scanf_s("%1d%1d%1d%1d%1d%1d%1d%1d%1d%1d%1d", &a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8, &a9, &a10, &a11);

b = a1 + a3 + a5 + a7 + a9 + a11;

bb = a2 + a4 + a6 + a8 + a10;

c = 9-(b * 3 + bb - 1) % 10;

printf(“Check digit: %d\n”,c);

system(“pause”);

return 0;

}

第六题

#include #include)

int main(void)

{

int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11,a12,b,bb,c;

printf(“Enter the first 12 digits of a EAN:”);

scanf_s("%1d%1d%1d%1d%1d%1d%1d%1d%1d%1d%1d%1d", &a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8, &a9, &a10, &a11,&a12);

bb = a1 + a3 + a5 + a7 + a9 + a11;

b = a2 + a4 + a6 + a8 + a10+a12;

c = 9-(b * 3 + bb - 1) % 10;

printf(“Check digit: %d\n”,c);

system(“pause”);

return 0;

}

dcc16fda53f4afa2e7e1d6e361491612.png

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值