我刚开始学c语言,刚用这个应用但写出这个程序却运行不了。(我下载到了d盘)求解答
语法错误
#include <stdio.h>
int main() {
printf("This is a c program.\n");
}
ctrl+f5编译下,代码没有明显错误
但是最好 int main() 而不是 void main
#include <bits/stdc++.h>
using namespace std;
const int N = 100;
const int mod = 1e9 + 7;
#define ll long long
double x1, mm, x2, y2, x3, y3, x4, y4;
double f(double x1, double mm, double x2, double y2, double x3, double y3)
{
double a = sqrt((x1 - x2) * (x1 - x2) + (mm - y2) * (mm - y2));
double b = sqrt((x1 - x3) * (x1 - x3) + (mm - y3) * (mm - y3));
double c = sqrt((x3 - x2) * (x3 - x2) + (y3 - y2) * (y3 - y2));
double s = (a + b + c) / 2.0;
double res = sqrt(s) * sqrt(s - a) * sqrt(s - b) * sqrt(s - c);
// double ans = sqrt(s * (s - a) * (s - b) * (s - c));
return res;
}
int main()
{
cin >> x1 >> mm >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
// cout << x1 << mm << x2 << y2 << x3 << y3 << x4 << y4;
double ans1, ans2, ans3, ans4;
double res;
ans1 = f(x1, mm, x2, y2, x3, y3) + f(x1, mm, x4, y4, x3, y3);
ans2 = f(x4, y4, x2, y2, x3, y3) + f(x1, mm, x4, y4, x2, y2);
ans3 = f(x4, y4, x1, mm, x3, y3) + f(x1, mm, x3, y3, x2, y2);
ans4 = f(x4, y4, x2, y2, x1, mm) + f(x3, y3, x4, y4, x2, y2);
res = min(ans1, ans2);
res = min(res, ans3);
res = min(res, ans4);
printf("%.3lf\n", res);
return 0;
}
公式代码:
#include <bits/stdc++.h>
using namespace std;
const int N = 110;
const int mod = 1e9 + 7;
#define ll long long
struct node{
int x, y;
}a[N];
int main()
{
double res = 0;
for(int i = 0; i < 4; i++){
cin >> a[i].x >> a[i].y;
}
a[4].x = a[0].x;
a[4].y = a[0].y;
for (int i = 0; i < 4; i++){
res += (a[i].x * a[i + 1].y - a[i + 1].x * a[i].y);
}
printf("%.3lf", fabs(res / 2.0));
return 0;
}