1
0
mirror of https://github.com/renbaoshuo/202401-programming-assignments.git synced 2024-12-16 15:44:39 +00:00
202401-programming-assignments/【实践课内】14.指针2/6-2 拆分实数的整数与小数部分.md

43 lines
893 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 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
```