c语言这几道题怎么解 50
1个回答
2018-06-21
展开全部
#include #include int numCnt(int num) { int nRet = 0; // 将数字转换成字符串,然后解析字符串即可 char chNum[10] = {'\0'}; char *p = chNum; sprintf(chNum, "%d", num); // 只要解析到就行了 while ('\0' != *p) { if ('1' == *(p++)) { nRet++; printf("yes to change [%d] - %d \n", num, nRet); } } return nRet;}int main(void){ int num; int nCnt = 0; printf("Please Input n : "); scanf("%d", &num); for (int i = 1; i / if (num >= 10) nCnt += 1; printf("the count is: %d\n", nCnt); return 0;}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询