我30你40他50”结果就是120
来源:互联网 发布:香港端口 编辑:程序博客网 时间:2024/04/30 00:40
/**//*++
Copyright (c) 2007 YourCompany
Module Name:
<new>
Abstract:
有一个字符串,里面包含一些数字,写一个函数,
把这些数字加起来。比如“我30你40他50”结果就是120。
Author:
YourName (YourEmail) 2007-06-12
Revision History:
--*/
#include<stdio.h>
#include<string.h>
#include<math.h>
#define MAX_LEN 30
int main(int argc, char* argv[])
...{
char str[MAX_LEN];
float num[MAX_LEN]; //数组定义后会自动初始化为0,为何还要用menset???
int count=-0;
char ch; //存放取出的字符
int i=0;
int j=0;
int n=0;
int Len; //记录输入串长度
double sum=0.0;
double result=0.0;
printf("[+]please input the string ");
printf("[-]example:你30岁我20岁一起是多少岁? ");
printf("[-]result: 50 ");
printf("please input the string in english or chinese: ");
gets(str);
Len=strlen(str);
printf("-----------:%f----------------------- ",pow(10.0,3.0));
printf("ur string is :%s the length is:%d ",str,Len);
while(Len!=0)
...{
ch=str[i];
printf("get char: %c ",ch);
if(ch>='0' && ch<='9')
...{
j=0;
count=-1;
while(ch>='0'&&ch<='9')
...{
printf("find the number: %c ",ch);
num[j]=(float)str[i++]; //强制类型转换,使字符型变为浮点
printf("turn char to float: %f ",num[j]);
count++;
j++;
Len--;
ch=str[i];
printf("get char: %c ",ch);
}
for(n=0;n<j;n++,count--) //取出数字
sum+=num[n]*pow(10.0,(float)count);
printf("fetch the number: %f ",sum);
}
else
...{
i++;
Len--;
}
result+=sum;
}
Copyright (c) 2007 YourCompany
Module Name:
<new>
Abstract:
有一个字符串,里面包含一些数字,写一个函数,
把这些数字加起来。比如“我30你40他50”结果就是120。
Author:
YourName (YourEmail) 2007-06-12
Revision History:
--*/
#include<stdio.h>
#include<string.h>
#include<math.h>
#define MAX_LEN 30
int main(int argc, char* argv[])
...{
char str[MAX_LEN];
float num[MAX_LEN]; //数组定义后会自动初始化为0,为何还要用menset???
int count=-0;
char ch; //存放取出的字符
int i=0;
int j=0;
int n=0;
int Len; //记录输入串长度
double sum=0.0;
double result=0.0;
printf("[+]please input the string ");
printf("[-]example:你30岁我20岁一起是多少岁? ");
printf("[-]result: 50 ");
printf("please input the string in english or chinese: ");
gets(str);
Len=strlen(str);
printf("-----------:%f----------------------- ",pow(10.0,3.0));
printf("ur string is :%s the length is:%d ",str,Len);
while(Len!=0)
...{
ch=str[i];
printf("get char: %c ",ch);
if(ch>='0' && ch<='9')
...{
j=0;
count=-1;
while(ch>='0'&&ch<='9')
...{
printf("find the number: %c ",ch);
num[j]=(float)str[i++]; //强制类型转换,使字符型变为浮点
printf("turn char to float: %f ",num[j]);
count++;
j++;
Len--;
ch=str[i];
printf("get char: %c ",ch);
}
for(n=0;n<j;n++,count--) //取出数字
sum+=num[n]*pow(10.0,(float)count);
printf("fetch the number: %f ",sum);
}
else
...{
i++;
Len--;
}
result+=sum;
}
- 我30你40他50”结果就是120
- 姥姥,,我跟你说个事,,就是吧,,我们出去了,,结果姥爷给忘了,,给我买鱿鱼吃了,,你说说,,他怎么给忘了呢,,我打预防针不能吃海鲜啊
- 方便你我他
- Monad你我他
- Monad你我他
- 你 我 他
- 就是继续,就是你 我还有过客
- 我你他的故事
- JAVA 输出 你 我 他
- 你就是我的唯一!
- 你就是我的风景
- 你就是我的风景
- 我就是爱你 爱着你
- 我就是我,希望带给你快乐
- 技术不如你,但老板就是赏识他,为什么?
- 技术不如你,但老板就是赏识他,为什么?
- 转:. 技术不如你,但老板就是赏识他,为什么?
- 遵守交通规则,方便你我他
- HTML和Javascript混合转义
- UNIX socket编程原理
- SWT Designer 6.0 (Window Builder Pro) 安装及注册方法
- 你是富人还是穷人
- X86汇编语言学习手记(1)
- 我30你40他50”结果就是120
- 进程线程的区别
- 内核编译中
- 人力资源的精彩故事
- (技巧篇)存储过程调试技巧搜集
- 古典诗词作业
- 卜算子·李之仪
- 彩书怨
- 对于万恶的脂肪的非暴力不合作运动正式打响,保持每天3200M / 全面进入最为激烈的期末考试+cet6复习阶段...