Write a C program to input an integer, and output how many times each digit occurs in the integer.

Recommended Answers

All 4 Replies

#include<stdio.h>
int main(void)
{
    int num, m, div=1, rem, count=0, i,n, a;
    printf("Enter Number: ");
    scanf("%d", &num);
    div=num;
    for(i=1; i<=10; i++)
    {
        div=num;
        while(div!=0)
        {
        rem=div%10;
        div=div/10;


        if(i==rem)
        {
            count++;
        }


        if(i==rem && count>=2)
        {
            printf("\n%d is present %d times", i, count);
        }
        }
    }
    return 0;
}

@basit_3 please refrain from just giving code to homework vultures. If they have a problem with code helping them is fine. Just give me the code questions should be ignored.

Should have been posted in the C forum.

leonardo123, firstly your question is in C not C++, so can we know why is it being asked in C++ forum ? Secondly, we're not here to do your homework. Show us your effort and we'll help you out.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.