본문 바로가기

C language

C language - 입력된 수의 3의 개수 찾기

C언어

문제 : 임의의 숫자를 입력받고 임의의 숫자에 3이란 숫자가 몇개 있는지 출력하시오.

#include <stdio.h>

int count_3(int x)
{
    int count=0;
    while(1)
    {
        if(x%10==3)
            count++;
        x/=10;

        if(x==0)
            break;

    }

    return count;
}

int main()
{
    int put,count;

    scanf("%d",&put);

    count = count_3(put);

    printf("%d",count);

}


return 0;