|
藍森林 http://www.lslnet.com 2006年6月6日 10:18
c語言如何將數取整。急!!!
如何將(exp((len-i+1)*ln(2)+0.5)取整。
謝謝。 |
c語言如何將數取整。急!!!
直接用(int)(exp((len-i+1)*ln(2)+0.5)強制轉換試試? |
c語言如何將數取整。急!!!
但是我這樣寫wi=(int)(exp((len-i+1)*ln(2)+0.5)%11為什麼報這個錯:
"/home/wucb/src/appl/acct/acc_xjzhwh.ec", line 647: error: Syntax error before or at: wi
請問如何修改達到我的目的。 |
c語言如何將數取整。急!!!
什麼環境啊,ln這個函數能用嗎?我怎麼不能用啊?好幾個主機上都沒有啊。 |
c語言如何將數取整。急!!!
sco unix環境 |
c語言如何將數取整。急!!!
我這裡沒有那個環境,這樣好了,你把exp((len-i+1)*ln(2)的結果給我,我幫你試試,我的主機是sun。 |
c語言如何將數取整。急!!!
不好意思,我LN可能不是C函數,LN是PASCAL中的函數,我將他用到C語言中。LN(X)是對數函數的意思。對數函數在C語言的對數函數是什麼呢? |
c語言如何將數取整。急!!!
不好意思我沒有找到那個求對數的函數(標準c裡好像有ln,但unix下好像沒有)我只好將ln(2)用計算器求出來代替一下,下面的程序在sun主機上實現的:
#include <iostream>;
#include <math.h>;
using namespace std;
int main (void)
{
int wi;
cout << ((int)(exp((8-3+1)*0.69314718055994530941723212145818+0.5)))%11 << endl;;
return 0;
}
結果是:6 |
c語言如何將數取整。急!!!
[code]
#include <math.h>;
Declaration:
double log10(double x);
Returns the common logarithm (base-10 logarithm) of x.
Range:
There is no range limit on the argument or return value.
Declaration:
double ceil(double x);
Returns the smallest integer value greater than or equal to x.
Range:
There is no range limit on the argument or return value.
Declaration:
double floor(double x);
Returns the largest integer value less than or equal to x.
Range:
There is no range limit on the argument or return value.
[/code] |
c語言如何將數取整。急!!!
各位老大出錯的時候可以看看裡面的說明吧?
好像是語法出錯了是不是????? |
c語言如何將數取整。急!!!
#include <math.h>;
double log(double) ;//求以e為底的對數
double log10(double) ;// 求以10為底的對數 |
| |