C++程序中为什么用cout输出float或double型的数据,屏幕上不是小数而是整数呢?
#include<iostream.h>voidmain(){inti=2;floatj=3.14;floata,b;a=float(i);b=(int)j;cout<<...
#include <iostream.h>
void main()
{
int i=2;
float j=3.14;
float a,b;
a=float(i);
b=(int)j;
cout<<"float型转换为int型:i="<<i<<",a="<<a<<endl;
cout<<"int型转换为float型:j="<<j<<",b="<<b<<endl;
}
#include <iostream.h>
void print(double d)
{
cout<<"This is a double "<<d<<"\n";
}
void print(int i)
{
cout<<"This is an integer "<<i<<"\n";
}
void main()
{
int x=1,z=10;
float y=1.0;
char c='a';
print(x);
print(y);
print(c);
print(double(z));
}
这两个程序输出的结果都是整数,但是在C里面float类型的数据明明可以输出小数的?求解?? 展开
void main()
{
int i=2;
float j=3.14;
float a,b;
a=float(i);
b=(int)j;
cout<<"float型转换为int型:i="<<i<<",a="<<a<<endl;
cout<<"int型转换为float型:j="<<j<<",b="<<b<<endl;
}
#include <iostream.h>
void print(double d)
{
cout<<"This is a double "<<d<<"\n";
}
void print(int i)
{
cout<<"This is an integer "<<i<<"\n";
}
void main()
{
int x=1,z=10;
float y=1.0;
char c='a';
print(x);
print(y);
print(c);
print(double(z));
}
这两个程序输出的结果都是整数,但是在C里面float类型的数据明明可以输出小数的?求解?? 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询