第一章 C++语言入门
1000:入门测试题目
提示
a + b 问题,要完全模仿老师的代码和写代码的操作。
不能有一点的创新。
代码
#include <iostream>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
cout << a + b;
return 0;
}
2060:【例1.1】计算机输出
代码
#include <iostream>
using namespace std;
int main() {
cout << "Hello World!";
return 0;
}
代码02
#include <cstdio>
using namespace std;
int main() {
printf("Hello World!");
return 0;
}
2061:【例1.2】梯形面积
代码
#include <cstdio>
using namespace std;
int main() {
int h = 150 * 2 / 15;
double s = 1.0 * (15 + 25) * h / 2;
printf("%.2lf\n", s);
return 0;
}
2062:【例1.3】电影票
代码
#include <iostream>
using namespace std;
int main() {
int x;
cin >> x;
cout << x << ' ' << x * 10 << '\n';
return 0;
}
2063:【例1.4】牛吃牧草
提示
牛吃牧草,是小学五年级的奥数问题,在教找等量关系,列方程。
我们编程题,在草稿纸上,完成计算后,如果能手算得到结果,代码直接输出结果,是可以的。
代码
#include <iostream>
using namespace std;
int main() {
cout << 10 << '\n';
return 0;
}
1001:Hello,World!
代码
#include <iostream>
using namespace std;
int main(){
cout << "Hello,World!" << '\n';
return 0;
}
1002:输出第二个整数
代码
#include <iostream>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
cout << b << endl;
return 0;
}
1003:对齐输出
提示
控制输出格式,我比较喜欢用printf
setw记不住
代码
#include <cstdio>
using namespace std;
int main() {
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
printf("%8d %8d %8d\n", a, b, c);
return 0;
}
1004:字符三角形
代码
#include <iostream>
using namespace std;
int main() {
char c;
cin >> c;
cout << ' ' << ' ' << c << '\n';
cout << ' ' << c << c << c << '\n';
cout << c << c << c << c << c << '\n';
return 0;
}
1005:地球人口承载力估计
代码
#include <iostream>
#include <cstdio>
using namespace std;
int main() {
int x, a, y, b;
cin >> x >> a >> y >> b;
double z = 1.0 * (a*x-b*y) / (a-b);
printf("%.2lf\n", z);
return 0;
}