MrRockchip

isPowerOfTen Number Alignment - Good Code ;-)

Feb 8th, 2013 (edited)
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.64 KB | None | 0 0
  1. int isPowerOfTen(int x)
  2. {
  3.   if ( x == 10
  4.     || x == 100
  5.     || x == 1000
  6.     || x == 10000
  7.     || x == 100000
  8.     || x == 1000000)
  9.   return 1;
  10.  
  11.   return 0;
  12. }
  13.  
  14. int count_numbers (int num) {
  15.   int count=0;
  16.   if (num == 0) count++;
  17.   while (num !=0) {
  18.     count++;
  19.     num/=10;
  20.   }
  21.   return count;
  22. }
  23.  
  24. int main() {
  25. // int size;
  26. // int array[size];
  27. // int counter;
  28. // int j, l;
  29.  
  30. l=count_numbers(size-1)-1;
  31. for (j=0; j<l; j++) printf(" ");
  32. printf("# : Value\n");
  33. for(counter = 0; counter < size; counter++) {
  34.     if (isPowerOfTen(counter)) l--;
  35.     for (j=0; j<l; j++) printf("0");
  36.  
  37.     printf("%i : %i\n", counter, array[counter]);
  38.     }
  39. }
Add Comment
Please, Sign In to add comment