纯数字字符串检验

 

题目内容:

按给定函数原型编程检查一个字符串是否全由数字组成。

int IsAllDigit(char p[]);/*若全由数字组成,则函数返回1,否则返回0*/

在主函数中,从键盘输入一个字符串(假设字符串的最大长度为20个字符),调用函数IsAllDigit(),检查该字符串是否全由数字组成,然后在主函数中根据函数IsAllDigit()的返回值输出相应的提示信息。

程序运行结果示例1:

Please input a string:

help456↙

The string is not digit string.

 

程序运行结果示例2:

Please input a string:

20150216↙

The string is digit string.

 

字符串输入提示信息:"Please input a string:\n"

输入格式:  字符串输入采用 gets()函数

输出格式:

判断是纯数字字符串:"The string is digit string."

判断不是纯数字字符串:"The string is not digit string."

为避免出现格式错误,请直接拷贝粘贴题目中给的格式字符串和提示信息到你的程序中。

时间限制:500ms内存限制:32000kb


 

#include <stdio.h>

#include <string.h>

int IsAllDigit(char a[])

{

int i, len;

len = strlen(a);

for (i=0; i<len; i++)

{

if (a[i]>=58 || a[i]<=47)

return 0;

}

}

int main()

{

char a[20];

int flag=0;

printf ("Please input a string:\n");

gets (a);

if (IsAllDigit(a) == 0)

printf ("The string is not digit string.");

else

printf ("The string is digit string.");

return 0;

}

 

  • 4
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值