Slip 29 - B) Write a program, which accepts a number n and displays each digit separated by tabs. Example: 6702 Output = 6 7 0 2

Solution:

#include<stdio.h>
int main()
{
      int digit, num,rem;
      printf("Enter positive integer number: ");
      scanf("%d", &num); 
     while(num>0)
         {
          rem=rem*10+num%10;
           num=num/10;
          }
      printf("\nYou have entered: ");
      while (rem > 0)
      {            digit = rem % 10; 
            printf("\t %d",digit);
            rem=rem/10;
      }
      return 0;
}

Post a Comment

0 Comments