/*****************************************************
copyright (C), 2014-2015, Lighting Studio. Co., Ltd.
File name:
Author:Jerey_Jobs Version:0.1 Date:
Description:
Funcion List:
*****************************************************/
copyright (C), 2014-2015, Lighting Studio. Co., Ltd.
File name:
Author:Jerey_Jobs Version:0.1 Date:
Description:
Funcion List:
*****************************************************/
#include <stdio.h>
int main()
{
float k; //定义循环变量i、辅助运算变量k、中间变量temp1,temp2和字符型数组s
int i = 0,temp1;
int m = 0,n = 0;
float temp2;
char s[1024];
int a[1024];
float b[1024];
{
float k; //定义循环变量i、辅助运算变量k、中间变量temp1,temp2和字符型数组s
int i = 0,temp1;
int m = 0,n = 0;
float temp2;
char s[1024];
int a[1024];
float b[1024];
printf("Enter a string : \n"); //提示用户输入字符串
scanf("%s",s);
scanf("%s",s);
while(s[i] != '\0')
{
while((s[i] >= '0' && s[i] <= '9') || s[i] == '.') //只有当遇到第一个整数时,进入循环
{
temp1 = 0;
temp2 = 0.0;
while(s[i] >= '0' && s[i] <= '9') //当没有遇到小数点之前,把他当作整形来计算
{
temp1 = temp1 * 10 + s[i] - '0';
i++;
}
if(s[i] == '.') //一旦遇到小数点,就开始进行小数点之后的浮点数运算
{
k = 0.1;
temp2 = temp1;
i++;
while(s[i] >= '0' && s[i] <= '9') //在小数点后的数字中一直进行运算
{
temp2 = temp2 + (s[i] - '0') * k;
k = k * 0.1;
i++;
}
b[n++] = temp2;
}
else //下一位如果不是小数点,就直接输出
{
a[m++] = temp1;
}
i++;
}
i++;
}
{
while((s[i] >= '0' && s[i] <= '9') || s[i] == '.') //只有当遇到第一个整数时,进入循环
{
temp1 = 0;
temp2 = 0.0;
while(s[i] >= '0' && s[i] <= '9') //当没有遇到小数点之前,把他当作整形来计算
{
temp1 = temp1 * 10 + s[i] - '0';
i++;
}
if(s[i] == '.') //一旦遇到小数点,就开始进行小数点之后的浮点数运算
{
k = 0.1;
temp2 = temp1;
i++;
while(s[i] >= '0' && s[i] <= '9') //在小数点后的数字中一直进行运算
{
temp2 = temp2 + (s[i] - '0') * k;
k = k * 0.1;
i++;
}
b[n++] = temp2;
}
else //下一位如果不是小数点,就直接输出
{
a[m++] = temp1;
}
i++;
}
i++;
}
printf("整形数有:\n"); //按照标准格式输出
for(i = 0;i < m;i++)
{
printf("%d ",a[i]);
}
printf("\n");
for(i = 0;i < m;i++)
{
printf("%d ",a[i]);
}
printf("\n");
printf("浮点形数有:\n");
for(i = 0;i < n;i++)
{
printf("%.3f ",b[i]);
}
printf("\n");
return 0;
}
for(i = 0;i < n;i++)
{
printf("%.3f ",b[i]);
}
printf("\n");
return 0;
}