Write a simple program that allows the user to type in a mark ( use gets and atoi ) and then prints the grade using the if-else statements .
1条回答 默认 最新
关注 一、atoi()——把字符串转换成整型数
考点:字符串转换为数字时,对相关ASCII码的理解。C实现:
#include <ctype.h> #include <stdio.h> int atoi (char s[]); int main(void ) { char s[100]; gets(s); printf("integer=%d\n",atoi(s)); return 0; } int atoi (char s[]) { int i,n,sign; for(i=0;isspace(s[i]);i++)//跳过空白符; sign=(s[i]=='-')?-1:1; if(s[i]=='+'||s[i]==' -')//跳过符号 i++; for(n=0;isdigit(s[i]);i++) n=10*n+(s[i]-'0');//将数字字符转换成整形数字 return sign *n; }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 急matlab编程仿真二阶震荡系统
- ¥20 TEC-9的数据通路实验
- ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
- ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
- ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
- ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
- ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
- ¥15 python爬取bilibili校园招聘网站
- ¥30 求解达问题(有红包)
- ¥15 请解包一个pak文件