编程之美-2.6、精确表达浮点数
2013-04-15 09:50
267 查看
#include "stdafx.h"
#include<math.h>
#include<iostream>
using namespace std;
//求两数最大公约数
int g1(int x,int y)
{
return (!y)?x:g1(y,x%y);
}
int* change_float(int x, int y,int n,int m)
{
int a[2];
a[0]=x*(pow(10.0,m)-1)+y;
a[1]=((int)pow(10.0,m)-1)*((int)pow(10.0,n));
return a;
}
//long型的数据老是出错,还需调试
int _tmain(int argc, _TCHAR* argv[])
{
int x=3;
int y=33;
int n=1;
int m=2;
int a[2];
int *p;
p=change_float(x,y,n,m);
a[0]=*p;
a[1]=*(p+1);
cout<<a[0]<<" "<<a[1]<<endl;;
long g=g1(a[0],a[1]);
cout<<g<<endl;
cout<<a[0]<<" "<<a[1]<<endl;;
cout<<(a[0]/g)<<" "<<(a[1]/g);
return 0;
}
#include<math.h>
#include<iostream>
using namespace std;
//求两数最大公约数
int g1(int x,int y)
{
return (!y)?x:g1(y,x%y);
}
int* change_float(int x, int y,int n,int m)
{
int a[2];
a[0]=x*(pow(10.0,m)-1)+y;
a[1]=((int)pow(10.0,m)-1)*((int)pow(10.0,n));
return a;
}
//long型的数据老是出错,还需调试
int _tmain(int argc, _TCHAR* argv[])
{
int x=3;
int y=33;
int n=1;
int m=2;
int a[2];
int *p;
p=change_float(x,y,n,m);
a[0]=*p;
a[1]=*(p+1);
cout<<a[0]<<" "<<a[1]<<endl;;
long g=g1(a[0],a[1]);
cout<<g<<endl;
cout<<a[0]<<" "<<a[1]<<endl;;
cout<<(a[0]/g)<<" "<<(a[1]/g);
return 0;
}
相关文章推荐
- 读书笔记之编程之美 – 2.6 精确表达浮点数
- [编程之美] 2.6 精确表达浮点数
- 编程之美--2.6 精确表达浮点数
- 【编程之美】2.6精确表达浮点数
- 【编程之美】2.6 精确表达浮点数
- [编程之美] PSet2.6 精确表达浮点数
- 编程之美-2.6-精确表达浮点数
- 编程之美2.6——精确表达浮点数
- 2.6 精确表达浮点数
- 编程之美:第二章 数字之魅 2.6精确表达浮点数
- 编程之美 set 2 精确表达浮点数
- 编程之美--精确表达浮点数
- 精确表达浮点数 -- 编程之美
- 重新开始战斗11-编程之美-精确表达浮点数
- 编程之美读书笔记2.6—精确表达浮点数
- 编程之美2.6 精确表达浮点数
- 编程之美2.6 精确表达浮点数
- 《编程之美》学习笔记——2.6精确表达浮点数
- 编程之美 2.6 精确表达浮点数
- 2.6-精确表达浮点数