程序代码:
问题2, 可以计算把圆分成 3 ~ 1000 份时各种三角形的个数。解此题只需输入 10 即可 #include <stdio.h> int main() { int acute_t_cnt = 0, obtuse_t_cnt = 0, right_t_cnt = 0, i, j, slices; // acut: 锐角, right:直角, obtuse: 钝角 printf("How many slices do you want to cut a circle into? ( >=3 && <=1000 ) "); scanf("%d", &slices); while (slices < 3 || slices > 1000) { printf("You must be kidding, please give me a natural number ( >=3 && <=1000 ): "); scanf("%d", &slices); } for (i = 2; i < slices / 2; i++) { obtuse_t_cnt += slices / 2 - i; } obtuse_t_cnt *= 10; if (slices % 2 == 0) { right_t_cnt = (slices / 2 - 1) * slices; } else { right_t_cnt = 0; } acute_t_cnt = slices * (slices - 1) * (slices - 2) / 6 - obtuse_t_cnt - right_t_cnt; printf("\nWhen cut into %d slices, there would be\n\t%d acute triangles\n\t%d right triangles\n\t%d obtuse triangle\nwith their vertexes overlapping the cutting points.\n\n", slices, acute_t_cnt, right_t_cnt, obtuse_t_cnt); return 0; }
[ 本帖最后由 voidx 于 2011-4-17 23:48 编辑 ]