c语言编程:编程统计数字4在一个数中出现的次数。比如4在144中出现了2次。

输入格式:
直接输入一个长整型整数,没有其他任何附加字符。
输出格式:
直接输出结果,没有其他任何附加字符。
输入样例:
144
输出样例:
2

#include<stdio.h>

int main(){
    long int n;
    int count,i=0;
    while(scanf("%ld",&n)!=EOF){
        count=0;
        while(n){
            if(n%10==4) count++;
            n/=10;
        }
        printf("%d\n",count);
    }
}

温馨提示:答案为网友推荐,仅供参考
相似回答