2021-11-10

第1章 编程如此简单
1.2整数算术计算
P8页
(1)300公顷
解:
求1台拖拉机1天耕地公顷数:90÷3÷3=10(公顷)
求5台拖拉机6天耕地公顷数:10×5×6=300(公顷)
综合算式: 90÷3÷3×5×6=300(公顷)

#include <iostream>
using namespace std;

int main(){
	cout<<"5台拖拉机6天能耕:";
	cout<<90/3/3*5*6<<"公顷地。"<<endl; 
	return 0;
}

(2)3次
解:
求1辆车1次可以运送的钢材量:100÷4÷5=5(吨)
求7辆车运送105吨钢材的次数: 105÷(5×7)=3(次)
综合算式: 105÷((100÷4÷5)×7)=3(次)

#include <iostream>
using namespace std;

int main(){
	cout << "7辆车运送105吨钢材需要:";
	cout << 105/((100/4/5)*7) << "次" << endl; 
	return 0;
}

(3) 去掉2根,每班7根
解:
求每个班分到的绳子数:58÷8=7(根)…2(根)
分到7根,余下两根

#include <iostream>
using namespace std;

int main(){
	cout<<  "每个班最少要去掉" << 58%7 << "根跳绳。" <<endl;
	cout << "每个班分到" << 57/7 <<"根跳绳" << endl; 
	return 0;
}

1.3 实数算术计算
(1)1.92元
解:
求每只铅笔的价格:0.6÷5=0.12(元)
求16只铅笔的价格: 0.12×16=1.92(元)
综式:16×(0.6÷5)=1.92(元)

#include <iostream>
using namespace std;

int main(){
	cout << "购买16只铅笔需要" << (0.6/5)*16 << "元" << endl; 
	return 0;
}

(2)904套
解:
求原来需要的布的量:3.2×791=2531.2(m2)
求改进后能做的量:2531.2÷2.8=904(套)
综式:3.2×791÷2.8=904(套)

#include <iostream>
using namespace std;

int main(){
	cout << "现可以做:" << 3.2*791/2.8 << "套" << endl; 
	return 0;
}

(3)8厘米
解:
求出正方形的面积:10×8−16=64(m2)
求出正方形的边长:64−−√=8(m)
综式:10×8−16−−−−−−−−−√=8(m)

#include <iostream>
#include <cmath>
using namespace std;

int main(){
	cout << "正方形瓷砖边长为:" << sqrt(10*8-16) <<"厘米" << endl; 
	return 0;
}

第2章 数据的存储和读入
1)

变量名 是否合法
3zh 否,数字不能开头
ant 是
_3cq 是
my 是
friend 否,friend是友元函数关键字
Mycar 是
my_car 是
all 是
55a 否,数字不能开头
a_abc 是
while 否,while是循环关键字
daf-32 否,’-‘不能构成变量名
x.13 否,’.‘不能构成变量名
Var(3) 否,()不能构成变量名
maxn 是
max&min 否,’&'不能构成变量名
(2) 略(3)略

** 2.2 赋值语句和数学表达式**
(1) C

(2)

(A)y=m*x+b

(B)m=(a+b+c)/(e*f)

©a=sqrt((x-3*y)*z)

(D)a=(2x-y)/(x+yy)

(E)m=(x-y*z)/(2/c)

(3) C、E
(4):
表达式 值
++x x=11
–x x=9
y=x++ y=10 ,x=11
y=–x y=9,x=9
x++ x=11
x-- x=9
y=5*x++ y=50,x=11
y=x–*2+3 y=23,x=9
(5)
5-1:4 3 4 4 4 3
5-2: 2 0
(6)
ceil(3.14)=4, floor(3.14)=3 , 4^3.0=64 , sqrt(9)=3

#include <iostream>
#include <cmath>
using namespace std;

int main(){
	cout << "5年级分到" << 540/(120+150)*120 << "棵树苗" << endl;
	cout << "6年级分到" << 540/(120+150)*150 << "棵树苗" << endl;
	return 0;
}

2.3 数据类型转换
(1)1-1 3 3 3 8 11 8 c=1 c=1.375
1-2 3129,65,65,65.2,A

(2)

#include <iostream>
#include <cmath>
using namespace std;
int main(){
	char c;
	cin >> c;
	cout << char('a'+'z'-c);
	return 0;
}

2.4 变量的读入

(1)温度转换

#include <iostream>
#include <cstdio>
using namespace std;

int main(){
	double f;
	cin >> f;
	printf("%.4f",(f-32)*5/9); 
	return 0;
}

(2)三角形
利用
海伦公式
s=sqrt(p(p-a)(p-b)(p-c))
p=(a+b+c)/2

include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

int main(){
	double a,b,c;
	cin >> a >> b >> c;
	double p = (a + b + c) / 2;
	printf("%.4f",sqrt(p * (p-a) * (p-b) * (p-c)));
	return 0;
}

(3)猜数游戏

#include <iostream>
#include <cstdio>
using namespace std;

int main(){
	int x;
	cin >> x;
	x = x * 1000 + x;
	cout << x / 7 / 11 / 13; 
	return 0;
}

2.5 C语言中的scanf语句和printf语句
(1)

1-1
a=202
2*a=404
a=202
2323.343450
2323.34
2323.34
2323.34
1-2
1, 1,001,123,123 ,00123

2.6 顺序结构程序设计实例
(1)填充矩形

#include <iostream>
#include <cstdio>
using namespace std;

int main(){
	long long n,m,a;
	cin >> n >> m >> a;
	cout << (m * n) / (a*a); 
	return 0;
}

(2)存款收益

#include <iostream>
#include <cstdio>
using namespace std;

int main(){
	int a,b,c;
	cin >> a >> b >> c;
	cout << 20 - a - b - c; 
	return 0;
}

(4)计算余数

#include <iostream>
#include <cstdio>
using namespace std;

int main(){
	double a,b;
	cin >> a >> b;
	printf("%.2f",a - int(a / b) * b);
	return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值