# include <stdio.h>
# include <math.h>
int main(void)
{
int a = 4 ;
int b = 5 ;
int c = 9 ;
double delta ;
double x1 ;
double x2 ;
delta = b*b - 4*a*c ;
if (delta > 0)
{
x1 = (-b + sqrt(delta)) / (2*a) ;
x2 = (-b - sqrt(delta)) / (2*a) ;
printf("x1 = %f, x2 = %f\n",x1 ,x2) ;
}
else if (delta == 0)
{
x1 = (-b) / (2*a) ;
x2 = x1 ;
printf("x1 = x2 = %f\n",x1) ;
}
else (delta < 0)
{ //error C2143: 语法错误 : 缺少“;”(在“{”的前面
printf("无解\n") ;
}
return 0 ;
}
按你说的改的话就出现
1>MSVCRTD.lib(crtexew.obj) : error LNK2019: 无法解析的外部符号 _WinMain@16,该符号在函数 ___tmainCRTStartup 中被引用
1>Debug\yyecfc.exe : fatal error LNK1120: 1 个无法解析的外部命令
我用的是VC 6 没什么问题
你用的什么?
VS 2008
追答你是直接把这代码贴进去的?
我这里也有vs2008 我试试
你用vs2008 建 win32 控制台 如果你不选择 空项目
那么 main函数就需要用 nt _tmain(int argc, _TCHAR* argv[])
还需要调 多字符集
这个是我在vs2008下调好的 你贴进去试试
// ceshivc6.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
# include
# include
int _tmain(int argc, _TCHAR* argv[])
{
int a = 4 ;
int b = 5 ;
int c = 9 ;
double delta ;
double x1 ;
double x2 ;
delta = b*b - 4*a*c ;
if (delta > 0)
{
x1 = (-b + sqrt(delta)) / (2*a) ;
x2 = (-b - sqrt(delta)) / (2*a) ;
printf("x1 = %f, x2 = %f\n",x1 ,x2) ;
}
else if (delta == 0)
{
x1 = (-b) / (2*a);
x2 = x1;
printf("x1 = x2 = %f\n",x1) ;
}
else if(delta < 0)
{ //error C2143: 语法错误 : 缺少“;”(在“{”的前面
printf("无解\n") ;
}
getchar(); //不加这个结果一闪就没
return 0;
}
我是新手,,我看不懂“nt _tmain(int argc, _TCHAR* argv[])”
追答在vs2008中 这个 int _tmain(int argc, _TCHAR* argv[])
相当于 vc6 中的 main()函数
运行后CMD
一闪就没了。。。
加 }
getchar(); //不加这个结果一闪就没
return 0;
}
按你说的改的话就出现
1>MSVCRTD.lib(crtexew.obj) : error LNK2019: 无法解析的外部符号 _WinMain@16,该符号在函数 ___tmainCRTStartup 中被引用
1>Debug\yyecfc.exe : fatal error LNK1120: 1 个无法解析的外部命令
不是吧?确定下是不是用中文输入法输入的符号?
全部用英文输入一下,
else if(delta < 0)
{ //error C2143: 语法错误 : 缺少“;”(在“{”的前面
printf("no solution\n") ;
}
这样不应该出错的
我保证全是用英文符号写的,我用的VS2008
追答link错误,缺少库,或者是头文件的问题吧
可能是sqrt函数导致的
注掉sqrt试试
注掉sqrt,是可以运行了,但是根号不用sqrt怎么表示啊