求助,请指点一下代码规范
查看原帖
求助,请指点一下代码规范
881577
zx142407789楼主2023/3/12 14:26

怎么样写风格良好规范的代码

#include<iostream>
using namespace std;
void edgesort(int* ar,int n);
int NotTri(int x,int y,int z);
int isright(int x, int y, int z);
int isAcute(int x, int y, int z);
int isisotri(int x, int y, int z);
int iseqtri(int x, int y, int z);
int main() {
	int edge[3];
	for (int i = 0; i < 3; i++) {
		cin >> edge[i];
	}
	edgesort(edge,3);
	int a = edge[0], b = edge[1], c = edge[2];
	if (NotTri(a, b, c)) {
		cout << "Not triangle";
		return 0;
	}
	if (isright(a, b, c)) 
		cout << "Right triangle" ;
	else if (isAcute(a, b, c)) 
		cout <<"Acute triangle";
	else 
		cout << "Obtuse triangle";

	if (isisotri(a, b, c)) {
		cout << endl;
		cout << "Isosceles triangle";
		if (iseqtri(a, b, c)) {
			cout << endl;
			cout << "Equilateral triangle";
		}
	}
	return 0;
}
void edgesort(int* ar,int n) {
	int temp = 0;
	for (int i = 0; i < n - 1; i++) {
		for (int j = i + 1; j < n; j++) {
			if (ar[i] > ar[j]) {
				temp = ar[j];
				ar[j] = ar[i];
				ar[i] = temp;
			}
		}
	}
}
int NotTri(int x, int y, int z) {
	if (x + y > z) 	return 0;
	else return 1;
}
int isright(int x, int y, int z) {
	if (x * x + y * y == z * z)
		return 1;
	else return 0;
}
int isAcute(int x, int y, int z) {
	if (x * x + y * y > z * z) return 1;
	else return 0;
}
int isisotri(int x, int y, int z) {
	if (x == y || x == z || y == z) return 1;
	else return 0;
}
int iseqtri(int x, int y, int z) {
	if (x == y && x == z) return 1;
	else return 0;
}
2023/3/12 14:26
加载中...