#include <stdio.h>#define MAX_LEN 25 /* 字符串字符个数 */int Count(char s[]); /* 计算函数声明 */main(){ int i; int count = 0; char ch; char str[MAX_LEN+1]; /* 字符数组 */ str[MAX_LEN] = '\0'; /* 字符串结束标识符 */ clrscr(); /* tuirbo c 2.0 清屏函数 */ printf("input a string : "); for (i=0;i<MAX_LEN;i++) { /* 接收字符串 */ ch = getchar(); if (ch=='\n') break; str[i] = ch; } str[i] = '\0'; /* 当前字符串结束标识符 */ count = Count(str); /* 调用计数函数 */ printf("count:%d",count); /* 打印结果 */}int Count(char s[]){ int i; int c = 0; for (i=0;s[i]!='\0';i++) { if(s[i]>='0'&&s[i]<='9') c++; /* 判断并计数 */ } return c;}/* 晚安 See you tomorrow !*/
#include <stdio.h>int fun(char s[]){ int i=0; while(*s) { if(*s>='0'&&*s<='9')i++; s++; } return i;}int main(){ char s[200]; gets(s); printf("%d",fun(s)); return 0;}
#include<stdio.h>fun(char s[]){int i=0; while(s[i]!='\0') i++; return(i);}main(){char s[80]; scanf("%s",s); printf("%d\n",fun(s));}
#include <stdio.h>#include <ctype.h>#include <string.h>enum{MAX = 100};int fun(char s[]){ int count = 0; for(int i = 0; i < strlen(s); i++) if(isdigit(s[i])) count++; return count;}int main(void){ char s[MAX]; gets(s); printf("%d\n", fun(s)); return 0;}