Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- number_of_digits_without_using_loop_v1.c
- https://en.wikipedia.org/wiki/Logarithm
- https://www.mathsisfun.com/algebra/logarithms.html
- log(10) = 1
- log(100) = 2
- log(1000) = 3
- log(10000) = 4
- . . .
- You can find all my C programs at Dragan Milicev's pastebin:
- https://pastebin.com/u/dmilicev
- */
- #include <stdio.h>
- #include <math.h> // for log10()
- int main(void)
- {
- long long num = 999999991234567890;
- int count = 0;
- //count = ( num == 0 ) ? 1 : ( log10(num)+1 ); // or
- if( num == 0 )
- count = 1;
- else
- count = log10(num)+1;
- printf("\n In number %lld there are total digits %d \n", num, count);
- printf("\n In number %llu there are total digits %d \n", num, count);
- return 0;
- } // main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement