57 lines
1.1 KiB
Markdown
57 lines
1.1 KiB
Markdown
### C语言-1
|
|
|
|
```c
|
|
/*---------------------------------------------------------
|
|
【程序设计】程序将由数字字符组成的字符串转换为10进制实数,
|
|
例如将"123.4567"转换为123.45670。
|
|
|
|
输出如下:
|
|
123.45670
|
|
0.12345
|
|
4567.00000
|
|
------------------------------------------------------------------------
|
|
注意:部分源程序给出如下。请勿改动主函数main或其它函数中给出的内容,仅在
|
|
Program-End之间填入若干语句。不要删除标志否则不得分。
|
|
---------------------------------------------------------*/
|
|
#include<stdio.h>
|
|
#include<ctype.h>
|
|
double conver(char s[]){
|
|
int I,i,poi;
|
|
double F,p;
|
|
F=I=i=poi=0;
|
|
p=0.1;
|
|
/**********Program**********/
|
|
while(s[i] != '.'){
|
|
I*=10;
|
|
I+=s[i]-48;
|
|
i++;
|
|
}
|
|
i++;
|
|
while(s[i] != '\0'){
|
|
F+=(s[i]-48)*p;
|
|
p*=0.1;
|
|
i++;
|
|
}
|
|
|
|
|
|
|
|
/********** End **********/
|
|
return I+F;
|
|
}
|
|
int main()
|
|
{
|
|
char d[3][15]={"123.4567","0.12345","4567.0"};
|
|
int i;
|
|
for(i=0;i<3;i++)
|
|
printf("%12.5f\n",conver(d[i]));
|
|
return 0;
|
|
}
|
|
|
|
```
|
|
|
|
### C语言-2
|
|
|
|
```c
|
|
```
|
|
|