C++头文件问题

来源:百度知道 编辑:UC知道 时间:2024/06/06 08:28:33
#include <iostream>
#include <math>
using namespace std;
int greatest_common_divisor(int a,int b)
{
int i;
for(i=a;i>1;i--)
if(mod(b/i)||mod(a/i))
break;
return(i);
}
void main()
{
int a,b,c,d;
cout<<"please input two nembers,a and b:"<<endl;
cin>>a>>b;
if(a>b)
{
d=a;a=b;b=d;
}
c=greatest_common_divisor(a,b);
cout<<"the greatest common divisor is "<<c<<endl;
}
编译的时候说是找不到math这个文件,要怎样搞??
改成math.h了,也将mod改成fmod了,但又有新问题了error C2660: 'fmod' : function does not take 1 parameters,这是什么意思?

fmod需要两个参数, 除数与被除数, 我不知道C语言里这个函数怎么用的, 不过那个错误就是这个意思. 是不是写成mod(b,i)呢?

写成#include <math.h>试试。