pow函数,gets输入数字后的处理
来源:互联网 发布:机房网络布线 编辑:程序博客网 时间:2024/05/02 08:43
/*
输入一个整数n和一个字符串str,计算并输出n进制数str的值。
如输入:7 16
则输出:13 (16)7=(13)10
如输入:16 3A
则输出:58
在这里遇到一个问题 , 用gets输入函数 输入的字符串打印出来为ASCII的值
所以应该全部减去 ‘0’ 就对了
*/
#include"stdio.h"
#include"string.h"
#include"math.h"
int main()
{
char str[20];
int i,c;
int count=0;
int j;
// scanf("%d",&j);
// printf("j的值=%d",j);
gets(str);
c=strlen(str);
printf("字符串的长度= %d",c);
for(i=0;i<c;i++)
{
// printf("测试%d\n",str[i]-'0');
if(str[i]<='Z'&&str[i]>='A') //如果输入为16进制
str[i]=str[i]-'A'+10; //减去A +10 A=10
else
str[i]=str[i]-'0';
}
for(i=0;i<c;i++)
{
count=count+str[i]*pow(2,c-i-1); //2代表2进制
//count=count+7*str[i];
}
printf("count=%d",count);
}
输入一个整数n和一个字符串str,计算并输出n进制数str的值。
如输入:7 16
则输出:13 (16)7=(13)10
如输入:16 3A
则输出:58
在这里遇到一个问题 , 用gets输入函数 输入的字符串打印出来为ASCII的值
所以应该全部减去 ‘0’ 就对了
*/
#include"stdio.h"
#include"string.h"
#include"math.h"
int main()
{
char str[20];
int i,c;
int count=0;
int j;
// scanf("%d",&j);
// printf("j的值=%d",j);
gets(str);
c=strlen(str);
printf("字符串的长度= %d",c);
for(i=0;i<c;i++)
{
// printf("测试%d\n",str[i]-'0');
if(str[i]<='Z'&&str[i]>='A') //如果输入为16进制
str[i]=str[i]-'A'+10; //减去A +10 A=10
else
str[i]=str[i]-'0';
}
for(i=0;i<c;i++)
{
count=count+str[i]*pow(2,c-i-1); //2代表2进制
//count=count+7*str[i];
}
printf("count=%d",count);
}
0 0
- pow函数,gets输入数字后的处理
- C语言的字符串输入gets()函数
- 处理Linux下gets()字符输入函数不能运行问题
- C语言字符串输入,gets函数的缺点以及解决方法
- 字符串输入gets和fgets函数的区别
- 字符串输入函数,scanf,gets,fgets的用法和区别
- 关于Ext.form.NumberField中输入一个超大数字,失去焦点后变成另一个数字的bug的处理
- pow函数的用法
- pow函数的用法
- php的pow函数
- pow()函数的应用
- pow函数的用法
- gets函数的漏洞
- gets函数的问题
- gets函数的漏洞
- gets()函数的应用
- gets()函数的应用
- gets函数的使用
- 学习Spring Cloud第六课(将微服务注册到Eureka Server上)
- win7中安装ipython,并设置环境变量
- 栈的链式存储结构
- Vue2+VueRouter2+webpack 构建项目实战(五)配置子路由
- Lisp学习--Windows下面的开发环境搭建
- pow函数,gets输入数字后的处理
- 浅谈对协程的理解
- 学习Spring Cloud第七课(Ribbon的基本使用)
- java注解的使用方法
- java中final与static的使用场景
- 【第十九课】GUI---内部类的使用
- set
- BZOJ 3675: [Apio2014]序列分割
- 解决java.lang.VerifyError