Determine\detect whether the input string is a pure number!

Determine\detect whether the input string is a pure number!

#include <stdio.h>

int checknum(char* num)
{
    
    
	int i;
	for( i= 0;num[i]; i++)
	{
    
    
		if(num[i] > '9' || num[i] <  '0')//遍历所有字符检测是否为数字
		{
    
    
			printf("字符串不是纯数字\n");
			return 0;
		}
	
	}
	printf("字符串是纯数字\n");
	return 1;
}

int main()
{
    
    
char j[50];//字符串大小设置了50
printf("输入数字:\n");
scanf("%s",j);//获取为字符串类型
checknum(j);
system("pause");
return 0;
}

Guess you like

Origin blog.csdn.net/weixin_40071463/article/details/126311695