我是 C 新手,我编写了这个程序,但遇到错误 “(函数)的冲突类型” “(函数)的先前声明在这里”。
我在我的系统上使用命令提示符使用 Dev c++ 的 gcc 编译器编译了这个。 谁能帮助我理解我的错误?
#include<stdio.h>
#include<math.h>
main()
{
int a,b,c;
float area;
float ar(int a,int b,int c);
printf("Enter the lenghts of the three sides of a triangle");
scanf("%d%d%d",&a,&b,&c);
area=ar(a,b,c);
printf("The are a of the triangle is=%.2f",area);
}
ar(a,b,c)
{
float area,s;
s=(a+b+c)/3;
area=sqrt((s*(s-a)*(s-b)*(s-c)));
return area;
}
最佳答案
您声明了函数“ar”,其返回类型为 float 但 float ar(int a,int b,int c);但你定义它时没有返回值。这就产生了一个问题。 试试这个:
#include<stdio.h>
#include<math.h>
float ar(int a,int b,int c);
void main()
{
int a,b,c;
float area;
printf("Enter the lenghts of the three sides of a triangle");
scanf("%d%d%d",&a,&b,&c);
area=ar(a,b,c);
printf("The are a of the triangle is=%.2f",area);
}
float ar(int a,int b,int c)
{
float area,s;
s=(a+b+c)/3;
area=sqrt((s*(s-a)*(s-b)*(s-c)));
return area;
}
使用命令编译:gcc -std=c99 -o stack_16_4_16 stack_16_4_16.c -lm
关于c - 我的 gcc 编译器给了我一个错误,显示为(函数)的类型冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36663061/