第一题
#include <iostream>
int main() {
double a, b, c, t;
std::cin >> a;
std::cin >> b;
std::cin >> c;
if (a >= b) {
if (b >= c) {}
else {
if (a >= c) {
t = c;
c = b;
b = t;
}
else {
t = a;
a = c;
c = b;
b = t;
}
}
}
else {
if (a >= c) {
t = a;
a = b;
b = a;
}
else {
if (b >= c) {
t = a;
a = b;
b = c;
c = t;
}
else {
t = a;
a = c;
c = t;
}
}
}
std::cout << a << ">" << b << ">" << c;
return 0;
}
第二题
#include<iostream>
#include<cmath>
int main() {
double a, b, c, p, S2;
std::cin >> a;
std::cin >> b;
std::cin >> c;
if (a + b > c && a + c > b && b + c > a) {
p = (a + b + c) / 2;
S2 = p * (p - a) * (p - b) * (p - c);
std::cout << sqrt(S2);
}
else {
std::cout << "Error";
}
return 0;
}
第三题
#include<iostream>
int main() {
int a = 1, b = 0, c = 0;
while (a < 10) {
b = 0;
while (b < 10) {
c = 0;
while (c < 10) {
if (a * 100 + b * 10 + c == a * a * a + b * b * b + c * c * c)
{std::cout << a * 100 + b * 10 + c << "\t";}
c += 1;}
b += 1;}
a += 1;}
return 0;
}
第四题
#include<iostream>
int main() {
int n, C;
do {
std::cin >> n;
if (n < 0)break;
C = n * (n + 1) / 2;
std::cout << C;
}while(n > 0);
return 0;
}
第五题
#include<iostream>
int main() {
int a = 1, b = 2, c = 3, d = 4;
std::cout << a << "\t" << a * 2 << "\t" << a * 3 << "\t" << a * 4 << "\t" << a * 5 << "\n";
std::cout << b << "\t" << b * 2 << "\t" << b * 3 << "\t" << b * 4 << "\t" << b * 5 << "\n";
std::cout << c << "\t" << c * 2 << "\t" << c * 3 << "\t" << c * 4 << "\t" << c * 5 << "\n";
std::cout << d << "\t" << d * 2 << "\t" << d * 3 << "\t" << d * 4 << "\t" << d * 5;
return 0;
}
第六题
#include<iostream>
int main() {
int i = 1,n=0,a,C=0;
while (i < 11) {
std::cin >> a;
if (a > 0) {
n += 1;
C = C + a;
}
i += 1;
}
std::cout << "正数有" << n << "个";
std::cout << "\n" << C / n;
return 0;
}
第七题
#include<iostream>
int main() {
int radius, area;
do {
std::cin >> radius;
if (radius < 1 || radius>10)
break;
else {
area = 3.1416 * radius * radius;
std::cout << area<<"\n";
}
}
while (area <= 100);
return 0;
}
第八题
#include<iostream>
int main() {
int n, i = 2;
std::cin >> n;
for(;i<n;i+=1)
{
if (n% i == 0) {
std::cout << n << "不是素数";
break;
} }
if (n / i == 1) {
std::cout << n << "是素数";
}
return 0;
}
第九题
#include<iostream>
int main() {
int n = 100, i = 2, c = 0;
while (n > 99 && n < 201) {
for (; i < n; i += 1){
if (n % i == 0) {
n += 1;
i = 2;
continue;
}
}
if (n / i == 1) {
std::cout << n << "\t \t \t ";
}
n += 1;
i = 2;
}
return 0;
}
第十题(不会)
#include<iostream>
int main() {
int n, i = 1;
std::cin >> n;
while (i <= n) {
std::cout << "*" * (2 * i - 1);
i += 1;
}
while (i <= 2 * n - 1) {
std::cout << "*" * (2 * n - i);
i += 1;
}
return 0;
}