mirror of
https://github.com/renbaoshuo/202401-programming-assignments.git
synced 2024-12-16 15:44:39 +00:00
43 lines
893 B
Markdown
43 lines
893 B
Markdown
# 6-2 拆分实数的整数与小数部分
|
||
|
||
本题要求实现一个拆分实数的整数与小数部分的简单函数。
|
||
|
||
### 函数接口定义:
|
||
```c++
|
||
void splitfloat( float x, int *intpart, float *fracpart );
|
||
```
|
||
其中`x`是被拆分的实数(0$$\le$$`x`$$<$$10000),`*intpart`和`*fracpart`分别是将实数x拆分出来的整数部分与小数部分。
|
||
|
||
### 裁判测试程序样例:
|
||
```c++
|
||
#include <stdio.h>
|
||
|
||
void splitfloat( float x, int *intpart, float *fracpart );
|
||
|
||
int main()
|
||
{
|
||
float x, fracpart;
|
||
int intpart;
|
||
|
||
scanf("%f", &x);
|
||
splitfloat(x, &intpart, &fracpart);
|
||
printf("The integer part is %d\n", intpart);
|
||
printf("The fractional part is %g\n", fracpart);
|
||
|
||
return 0;
|
||
}
|
||
|
||
/* 你的代码将被嵌在这里 */
|
||
```
|
||
|
||
### 输入样例:
|
||
```in
|
||
2.718
|
||
```
|
||
|
||
### 输出样例:
|
||
```out
|
||
The integer part is 2
|
||
The fractional part is 0.718
|
||
```
|