#include<stdio.h>
#include<math.h>
int main(void) {
double a1, a2, a3, a4, a5, a6, a7,s;
double area(double x, double y, double z);
printf("please input 7 side lengths in the order a1 to a7:\n");
scanf("%lf%lf%lf%lf%lf%lf%lf", &a1, &a2, &a3, &a4, &a5, &a6, &a7);
s = area(a1, a5, a6) + area(a4, a6, a7) + area(a2, a3, a7);
printf("THE area of the pentagon is %.2f\n", s);
return 0;
}
double area(double x, double y, double z) {
double p = (x + y + z) / 2;
return sqrt(p * (p - x) * (p - y) * (p - z));
}
定义三条边xyz三条形参分别接受三条实参的值,%.2f表示保留两位小数
sqrt函数即平方根函数,用于海伦秦九昭公式的计算
如何从一个输入的身份证号中获取他的出生年月日?
scanf("%6d%4d%2d%2d%4d",&a,&year,&moth,&day,&c);//从读取的整数中依次把前六位赋值给a
六位后的四位赋值给year,后两位赋值给moth,后两位赋给day,后四位赋给c,输出year,moth,day就能得到他的出生年月日了
printf("%d-%02d-%02d\n",year,moth,day);//%02d使得遇到0时可以填充,达到2位