C语⾔程序设计——现代⽅法(第2版)课后编程题答案
C语⾔程序设计——现代⽅法(第2版)课后编程题答案[作者:K.N.King 运⾏环境:visual studio 2019 c++]第⼆章⾄第六章
第⼆章
2.1 略
2.2-2.3
weighed题⽬:
解答:
#include<stdio.h>
#define pi 3.14
int main()
{
int r =0;
printf("请输⼊半径:");
scanf_s("%d",&r);
printf("球体体积为:%f\n",4.0f/3.0f* pi * r * r * r);
return0;
}
2.4
request的名词#include<stdio.h>
int main()
{
float a;
printf("Enter an amount:");
scanf_s("%f",&a);
printf("With tax added: $%.2f", a *1.05);
return0;
}
%f:105;
%1f:105.0;
%2f:105.00;
2.5-2.6
#include<stdio.h>
int main()
{
int x, y;
printf("请输⼊x:");
scanf_s("%d",&x);
y =((((3* x +2)* x -5)* x -1)* x +7)* x -6; printf("%d", y);
return0;
}
2.7
#include<stdio.h>
int main()
{
int money;insert怎么加where
int num20,num10,num5,num1;
printf("Enter a dollar amount:");
scanf_s("%d",&money);
num20 = money/20;
money = money-20*num20;
num10 = money/10;
money = money-10*num10;
num5 = money/5;
num1 = money%5;
printf("$20 bills: %d\n", num20);
printf("$10 bills: %d\n", num10);
printf(" $5 bills: %d\n", num5);
printf(" $1 bills: %d\n", num1);
return0;
}
2.8
#include<stdio.h>
冒泡排序代码c语言int main()
{
float money, rate, payment;
printf("Enter amount of loan:");
scanf("%f",&money);
printf("Enter interest rate:");
scanf("%f",&rate);
printf("Enter monthly payment:");
scanf("%f",&payment);
printf("Balance remaining after first payment:%.2f\n", money =((money - payment)+(money *0.01* rate /12))); printf("Balance remaining after second payment:%.2f\n", money =((money - payment)+(money *0.01* rate /12))); printf("Balance remaining after third payment:%.2f\n", money =((money - payment)+(money *0.01* rate /12))); return0;
}
第三章
3.1
#include<stdio.h>
int main()
{
int year, month, day;
printf("Enter a data(mm/dd/yyyy):");
scanf_s("%d/%d/%d",&month,&day,&year);
printf("You entered the date %d%.2d%.2d\n", year, month, day);
//%.2d表⽰⾄少要显⽰两位数![请添加图⽚描述]
return0;
}
3.2
#include<stdio.h>
int main()
{
int number;
float price;
int year, month, day;
printf("Enter item number:");
scanf_s("%d",&number);
printf("Enter unit price:");
scanf_s("%f",&price);
printf("Enter purchase date(mm/dd/yyyy):");
scanf_s("%d/%d/%d",&month,&day,&year);
printf("Item\tUnit\tPurchase\n \tPrice\tDate\n%d\t%.2f\t%d%.2d%.2d\n",number,price, year, month, day); return0;
}
3.3
#include<stdio.h>
int main()
{
int gp, gi, pc, in, cd;
printf("Enter ISBN:");
scanf_s("%d-%d-%d-%d-%d",&gp,&gi,&pc,&in,&cd); printf("Gs1 prefix: %d\n", gp);
printf("Group identifier: %d\n", gi);
printf("Publisher code: %d\n", pc);
printf("Item number: %d\n", in);
printf("Check digit: %d\n", cd);
return0;
}
3.4
#include<stdio.h>
int main(void)
{
int a, b, c;
printf("Enter phone number [(xxx)xxx-xxxx]: ");
scanf_s("(%d)%d-%d",&a,&b,&c);
printf("You entered %d.%d.%d", a, b, c);
return0;
volatile读法}
3.5
>undermining
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论