码迷,mamicode.com
首页 > 其他好文 > 详细

数据有效位

时间:2018-08-02 11:14:54      阅读:132      评论:0      收藏:0      [点我收藏+]

标签:put   char   pre   argc   str   bsp   error   nbsp   pac   

 1 #include <iostream>
 2 #include <iomanip> 
 3 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
 4 
 5 using namespace std;
 6 int main(int argc, char** argv) {
 7      //float型变量的声明、输入、计算和输出
 8     float fx,fy;   
 9     cout<<"fx=";
10     cin>>fx;
11     cout<<"fy=";
12     cin>>fy;
13     cout<<fx<<"+"<<fy<<"="<<fx+fy<<endl;
14     cout<<fx<<"-"<<fy<<"="<<fx-fy<<endl;
15     cout<<fx<<"*"<<fy<<"="<<fx*fy<<endl;
16     cout<<fx<<"/"<<fy<<"="<<fx/fy<<endl<<endl;
17     //cout<<fx<<"%"<<fy<<"="<<fx%fy<<endl;  Error!
18 
19     //double型变量的声明、输入、计算和输出
20     float dx,dy;  
21     cout<<"dx=";
22     cin>>dx;
23     cout<<"dy=";
24     cin>>dy;
25     cout<<dx<<"+"<<dy<<"="<<dx+dy<<endl;
26     cout<<dx<<"-"<<dy<<"="<<dx-dy<<endl;
27     cout<<dx<<"*"<<dy<<"="<<dx*dy<<endl;
28     cout<<dx<<"/"<<dy<<"="<<dx/dy<<endl<<endl;
29     //cout<<fx<<"%"<<fy<<"="<<fx%fy<<endl;  Error!
30 
31     //测试float和double类型数据的有效位
32     fx=10.0;fy=6.0;
33     float fz=fx/fy;
34     dx=10.0;dy=6.0;
35     double dz=dx/dy;
36     cout<<"fz=";
37     cout<<setprecision(20)<<fx<<"/"<<fy<<"="<<fz<<endl;
38     cout<<"dz=";
39     cout<<setprecision(20)<<dx<<"/"<<dy<<"="<<dz<<endl<<endl;;
40 
41     //float型溢出
42     float x=3.5e14;
43     cout<<"x="<<x<<endl;
44     cout<<"x*x="<<x*x<<endl;
45     cout<<"x*x*x="<<x*x*x<<endl;
46     return 0;
47 }

 

数据有效位

标签:put   char   pre   argc   str   bsp   error   nbsp   pac   

原文地址:https://www.cnblogs.com/borter/p/9405652.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!