第一次上机作业

第一题

#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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值