i want seprate 1234 like 1,2,3,4
when i give 1234 then this code works fine but if i give long int like 34545666 this code does not work.

int main()
{
 clrscr();
 int num,r,c,sp,x;
 printf("enter number");
 scanf("%d",&num);
 while(num!=0)
 {
 x=num%10;
 printf("%d",x);
 num=num/10;
 }

My educated guess is that you're using Turbo C to run this program. Turbo C's int is 2 bytes rather than 4, so 34545666 is waaay out of range. Use a long int instead of int to ensure that the code works even on ancient compilers or compilers that target funky systems:

#include <stdio.h>

int main(void)
{
    long int num;

    printf("Enter a whole number: ");
    fflush(stdout);

    if (scanf("%ld", &num) == 1)
    {
        while (num != 0)
        {
            printf("%ld", num % 10);
            num /= 10;
        }

        puts("");
    }

    return 0;
}
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.