[問題] c語言資料型態的問題
# include "cv.h"
# include "highgui.h"
# include "math.h"
# include "iostream"
using namespace std ;
void main()
{
int x,y;
int a;
float sum;
float pdf=0;
float cdf=0;
int hel=0;
double he;
for(a=0;a<=255;a++)
{ sum=0;
for(x=0;x<=499;x++)
{ for(y=0;y<=499;y++)
{
if(a==cvGet2D(img, x, y).val[0])
sum++;
}
}
pdf= sum/250000;
cdf=cdf+pdf;
hel=cdf*255+0.5;
cout <<"he為 " <<he1<<endl;
he=hel/250000;
cout <<"he為 " <<he<<endl;
}
system( "PAUSE" ) ;
}
這邊我有個問題
因為我想要對he1四捨五入的動作
所以我宣告為
int he1
這樣子在he=he1/250000時
全部的he都會變成0
為什麼呢?
不這樣子的話
要怎麼對he1做四捨五入
--
╭╮ 《襄兒》 ζvictorina◣
╰● 我走過山的時候山不說話,我路過海的時候海不說話;
╭╮ 我坐著的毛驢一步一步滴滴答答,我帶著的倚天喑啞。
╰● 大家說我因為愛著神雕大俠,找不到所以在峨嵋安家; ▁
╭╮ 其實我只是喜歡此地的霧,像十六歲那年綻放的煙花。▉襄▏
╰● ——北大未名 AngleMiao ▇
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 163.30.170.207
→
11/08 07:52, , 1F
11/08 07:52, 1F
→
11/10 22:36, , 2F
11/10 22:36, 2F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章