Advertisement
tzanany

Dismantling number

Mar 16th, 2012
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.56 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main()
  5. {
  6.     int i, num, temp;
  7.     int *result = NULL ;
  8.  
  9.     printf("Please Enter A  Number\n");
  10.     scanf("%d",&num);
  11.     temp = num;
  12.  
  13.     // Making The Array
  14.     for(i=1;temp!=0;i++)
  15.     {
  16.         result = (int *) realloc(result, i * sizeof(int));
  17.         if( result == NULL)
  18.         {
  19.             printf("Not Enough Memory!!!\n");
  20.             return 0;
  21.         }
  22.  
  23.         result[i-1] = temp%10;
  24.         temp = temp/10;
  25.     }
  26.    
  27.     //Printing The Array
  28.     for(i-=2;i>=0;i--)
  29.     {
  30.         printf("%4d",result[i]);
  31.     }
  32.     printf("\n");
  33.  
  34.     //Free The Array
  35.     free(result);
  36.  
  37.     return 1;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement