当前位置:文档之家› 同济大学 C++ 程序设计实验篇

同济大学 C++ 程序设计实验篇


" << endl;
4.
#include <iostream> #define a 5.52 using namespace std; int main() { double r; cout << " " << endl; cin >> r; r = r * 1000; cout << " " << 4 * 3.14 * r * r * r * a / 3 << " system("pause"); return 0; }
C/C++
C/C++ 1 C/C++ 2 3 4 5 6 7 8 9 10
1 C/C++
1.
#include <iostream> using namespace std; int main() { int x; cin >> x; int y = x * x; cout << "x ^ 2 =" << y << endl; system("pause"); return 0; }
2.
#include <iostream> using namespace std; int main() { double a, b, h;
cout << " "; cin >> a >> b >> h; cout << " =" << (a + b) * h / 2 << endl; system("pause"); return 0; }
3.
#include <iostream> using namespace std; int main() { int a, b, c; cout << " "; cin >> a >> b >> c; cout << " " << (a + b + c) / 3 << " system("pause"); return 0; }
a = x; x = y; y = a; } cout << x << "<" << y << "<" << z << endl; system("pause"); return 0; }
5.
#include <iostream> using namespace std; int main() { double a, b; char x; cout << " cin >> a >> x >> switch (x) { case '+': cout << a << break; case '-': cout << a << break; case '*': cout << a << break; case '/': cout << a << break; } system("pause"); return 0; }
5.
#include <iostream> using namespace std; int main() { char c1, c2, c3; c1 = 'f'; c2 = 'l'; c3 = 'y'; c1 = c1 + 3; c2 = c2 + 3; c3 = c3 - 23; cout << c1 << c2 << c3 << endl; system("pause"); return 0; }
2.
#include <iostream> using namespace std; int main() { double x, y; cout << " " << endl; cin >> x; if (x < 10) y = 30; else if (x >= 10 && x < 50) y = 2.5 * x; else y = 2 * x; cout << " " << y << " " << endl; system("pause"); return 0; }
3
1.
#include <iostream> using namespace std; int main() { int x, y, r1, r2; cin >> x >> y; if (x == 0 || y == 0) cout << " " << endl; else { r1 = x / y; r2 = x % y; cout << " =" << r1 << " " << " =" << r2 << endl; } system("pause"); return 0; }
3.
#include <iostream> using namespace std; int main() { double x, y; cout << " x y "; cin >> x >> y; cout << (x * x + y * y >= 4 && x * x + y * y <= 16 ? 3.14 * (4 * 4 - 2 * 2) : 0) << endl;
system("pause"); return 0; }
4.
#include <iostream> using namespace std; int main() { double a, b, c, max; cout << " 3 "; cin >> a >> b >> c; max = a > b ? a : b; max = max > c ? max : c; cout << " =" << (a + b + c) / 3 << " " << " =" << max << endl; system("pause"); return 0; }
2.
#include <iostream> using namespace std; int main() { int a, b, c; cout << " "; cin >> a; for (b = 1, c = 1; b != 0; a = b) {
b = a / 10; c = a % 10; cout << c; } system("pause"); return 0; }
4
1.
#include <cmath> #include <iostream> using namespace std; int main() { double a, b, c, d; cout << " " << endl; cin >> a >> b >> c; d = b * b - 4 * a * c; if (d < 0) cout << " " << endl; else cout << "x1=" << (-b + sqrt(d) / (2 * a)) << "x2=" << (-b - sqrt(d)) / (2 * a) << endl; system("pause"); return 0; }
" << endl;
2
1.
#include <iosspace std; int main() { float s1, s2, s3; double aver; cout << " " << endl; cin >> s1 >> s2 >> s3; aver = (s1 + s2 + s3) / 3; aver = aver * 100 + 0.5; aver = (int)aver; aver = aver / 100; cout << " " << aver << endl; system("pause"); return 0; }
相关主题