Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- number_of_digits_without_using_loop_v2.c
- Version with recursion from Bishal Raj Bhattarai
- https://web.facebook.com/profile.php?id=100009001371943
- You can find all my C programs at Dragan Milicev's pastebin:
- https://pastebin.com/u/dmilicev
- */
- #include <stdio.h>
- int count_digits(long long x)
- {
- static int counter=0; // must be static because of recursion
- if( x > 0 )
- {
- count_digits(x/10);
- counter++;
- }
- return counter;
- }
- int main(void)
- {
- long long num = 999999991234567890;
- int count;
- count = count_digits(num);
- 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
RAW Paste Data
Copied
Advertisement