在标准答案的基础上改动的数据结构与算法分析习题1.3答案
来源:互联网 发布:本地ip和网络ip 编辑:程序博客网 时间:2024/04/29 06:40
#include<iostream>
using namespace std;
int IntPart(double N);
double DecPart(double N);
void PrintDigit(int ADigit);
void PrintOut(int n);
void PrintFractionPart(double FractionPart,int DecPlaces)//输入一个浮点型数据FractionPart,和整型DecPlaces
{
int i,ADigit;//设立整形i和ADigit,作用不明
int j=0;
for(i=0;i<DecPlaces;i++)//循环DecPlaces次
{
FractionPart*=10;//FractionPart为10*FractionPart
ADigit=IntPart(FractionPart);//Adigit等于FractionPart的整数部分
if(ADigit!=0)
j++;
PrintDigit(ADigit);//输出ADigit,即输出FractionPart的整数
FractionPart=DecPart(FractionPart);//FractionPart变为它自己的小数部分
}
printf("\n");
printf("%d",j);
}
void PrintReal(double N,int DecPlaces)//输入一个浮点数N,和整形数DecPlaces
{
int IntegerPart;//设立IntegerPart整形
double FractionPart;//设立浮点型FractionPart
if(N<0)//如果N<0
{
putchar('-');//输出到屏幕一个-
N=-N;//将N变为-N,即为正数
}
//N=RoundUp(N,DecPlaces);//N为N加上AmountToAdd
IntegerPart=IntPart(N);//IntegerPart为N的整数部分
FractionPart=DecPart(N);//FractionPart为N的小数部分
PrintOut(IntegerPart);//输出N的整数部分
if(DecPlaces>0)//如果DecPlaces大于0
putchar('.');//输出,到屏幕
PrintFractionPart(FractionPart,DecPlaces);//输出FractionPart不停乘10的数
}
int IntPart(double N)
{
int n=N;
return n;
}
double DecPart(double N)
{
int n=N;
double n1=N-n;
return n1;
}
void PrintDigit(int ADigit)
{
printf("%d",ADigit);
}
void PrintOut(int n)
{
if(n<0)
n=-n;
/*该整数的中间数都以正数打出*/
if(n >= 10)
{
PrintOut(n/10);
printf("%d", n%10);
} else //第一个数字按原样打出
printf("%d", n%10);
}
int main()
{
double i=-12.14;
int dec=1000;
PrintReal(i,dec);
system("pause");
}
using namespace std;
int IntPart(double N);
double DecPart(double N);
void PrintDigit(int ADigit);
void PrintOut(int n);
void PrintFractionPart(double FractionPart,int DecPlaces)//输入一个浮点型数据FractionPart,和整型DecPlaces
{
int i,ADigit;//设立整形i和ADigit,作用不明
int j=0;
for(i=0;i<DecPlaces;i++)//循环DecPlaces次
{
FractionPart*=10;//FractionPart为10*FractionPart
ADigit=IntPart(FractionPart);//Adigit等于FractionPart的整数部分
if(ADigit!=0)
j++;
PrintDigit(ADigit);//输出ADigit,即输出FractionPart的整数
FractionPart=DecPart(FractionPart);//FractionPart变为它自己的小数部分
}
printf("\n");
printf("%d",j);
}
void PrintReal(double N,int DecPlaces)//输入一个浮点数N,和整形数DecPlaces
{
int IntegerPart;//设立IntegerPart整形
double FractionPart;//设立浮点型FractionPart
if(N<0)//如果N<0
{
putchar('-');//输出到屏幕一个-
N=-N;//将N变为-N,即为正数
}
//N=RoundUp(N,DecPlaces);//N为N加上AmountToAdd
IntegerPart=IntPart(N);//IntegerPart为N的整数部分
FractionPart=DecPart(N);//FractionPart为N的小数部分
PrintOut(IntegerPart);//输出N的整数部分
if(DecPlaces>0)//如果DecPlaces大于0
putchar('.');//输出,到屏幕
PrintFractionPart(FractionPart,DecPlaces);//输出FractionPart不停乘10的数
}
int IntPart(double N)
{
int n=N;
return n;
}
double DecPart(double N)
{
int n=N;
double n1=N-n;
return n1;
}
void PrintDigit(int ADigit)
{
printf("%d",ADigit);
}
void PrintOut(int n)
{
if(n<0)
n=-n;
/*该整数的中间数都以正数打出*/
if(n >= 10)
{
PrintOut(n/10);
printf("%d", n%10);
} else //第一个数字按原样打出
printf("%d", n%10);
}
int main()
{
double i=-12.14;
int dec=1000;
PrintReal(i,dec);
system("pause");
}
0 0
- 在标准答案的基础上改动的数据结构与算法分析习题1.3答案
- 数据结构与算法描述(习题3答案)
- 数据结构与算法分析(java语言描述) 部分课后习题答案 第一章
- 数据结构与算法分析(C++语言版)_张琨版 第一章课后习题答案
- 数据结构与算法js描述(习题二答案)
- 数据结构与算法分析 习题1.1
- 在xUtils的基础上做的改动,Android多线程下载、断点下载
- JAVA——动态代理(在别人的基础上稍作改动)
- 数据结构与算法的分析
- 数据结构习题答案(全部算法)---严蔚敏版
- 数据结构与算法设计 习题2.7题 算法分析
- 习题9.18的答案
- 习题9.18的答案
- 数据结构与算法分析课后习题第三章(2)
- 数据结构与算法分析课后习题第三章(3)
- 数据结构与算法分析课后习题第三章(4)
- 数据结构与算法分析课后习题第三章(5)
- 数据结构与算法分析课后习题第三章(6)
- 分布式数据库中间件对比总结
- 谈谈对异常的理解
- Android-商品展示
- 浅谈 zookeeper+dubbo分布式服务
- 8086汇编学习之基础知识、通用寄存器、CS/IP寄存器与Debug的使用
- 在标准答案的基础上改动的数据结构与算法分析习题1.3答案
- 如何告别半途而废——韦东山嵌入式Linux视频学习笔记00
- 33. Search in Rotated Sorted Array
- echart中国地图跟省地图整合
- Circle in Square LightOJ
- 栈ADT
- C++ 模板学习总结(二)基本概念、实例化和具体化
- 字串和
- 【软考】设计模式-原型模式