Description
读入一个实数,输出实数的整数部分。注意该实数的位数不超过100位。输入的整数部分可能含有不必要的前导0,输出时应去掉,当然,若整数部分为0,则该0不能去掉。如输入0023.56732,输出应为23,而不是0023;0.123对应的输出应为0。当然输入也可能不含小数部分。 要求定义并使用rounding()函数,原型如下: char *rounding(char *p) { //将字符串p表示的实数取整后生成新的字符串,并由函数返回 }
Input
输入一个实数.
Output
输出整数部分。
Sample Input
0012345678900.56789
Sample Output
12345678900
HINT
Source
#include
#include
#include
#define N 105
//将字符串p表示的实数取整后生成新的字符串,并由函数返回
char *rounding(char *p);
int main()
{
char *p;
p=(char*)malloc(sizeof(char)*N);
gets(p);
printf("%s\n",rounding(p));
return 0;
}
char *rounding(char *p)
{
char *q;
while(*p=='0')
p++;
while(*p=='\0'||*p=='.')
p--;
q=strchr(p,'.');
if(q!=NULL)//找到小数点位置,并替换成\0;
*q='\0';
return p;
}
|