刚用,为什么这个程序无法运行

img

我刚开始学c语言,刚用这个应用但写出这个程序却运行不了。(我下载到了d盘)求解答

语法错误

img


代码

#include <stdio.h>

int main() {

  printf("This is a c program.\n");

}


ctrl+f5编译下,代码没有明显错误
但是最好 int main() 而不是 void main

不知道你这个问题是否已经解决, 如果还没有解决的话:
  • 这个问题的回答你可以参考下: https://ask.csdn.net/questions/7768760
  • 这篇博客你也可以参考下:C语言:读取文件中若干个身份证号,根据校验码判断身份证的有效性,输出非法身份证。
  • 您还可以看一下 黄强老师的30分钟彻底学会C语言指针视频教程课程中的 指针玩转一维数组小节, 巩固相关知识点
  • 除此之外, 这篇博客: 2018年江西理工大学C语言程序设计竞赛 D中的 题意就是给顶点求四边形面积,注意凸凹。比赛的时候不知道公式,就把凸凹两种情况都求出来,然后最小的就是正确答案。其实有多边形面积公式可以用。 部分也许能够解决你的问题, 你可以仔细阅读以下内容或跳转源博客中阅读:

    公式链接
    比赛代码:
    #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;
    }
    

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^