|
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- int main()
- {
- int mode = 0;
- double a = 0, b = 0, c = 0;
- double h = 0;
- int ch;
- puts("Please select the mode:");
- puts("1. The lengths of base and height are known");
- puts("2. Lengths of all edges are know");
- while(mode != 1 && mode != 2){
- if(scanf("%d", &mode) != 1)
- while((ch = getchar()) && ch != '\n')
- ;
- }
- if(mode == 1){
- puts("Please input the lengths pf base and height");
- scanf("%lf %lf", &a, &h);
- if(a > 0 && h > 0)
- printf("S = %f\n", a * h / 2);
- else
- puts("input error");
- }
- else{
- puts("please input the lengths of all edges");
- scanf("%lf %lf %lf", &a, &b, &c);
- if(a > 0 && b > 0 && c > 0
- && a + b > c && b + c > a && a + c > b){
- double p = (a + b + c) / 2;
- double s = sqrt(p * (p - a) * (p - b) * (p - c));
- printf("S = %f\n", s);
- }
- else
- puts("input error");
- }
- system("pause");
- return 0;
- }
复制代码 |
|