I can\'t figure out how to solve this practice problem. \"write a function num_d
ID: 3614278 • Letter: I
Question
I can't figure out how to solve this practice problem."write a function num_digits(n) that returns the number ofdigits in n. (to determine number of digits, divide it by 10repeatedly.)
this is what I have, but it's not working properly and I knowi have a mistake, just can't figure out where.
#include <stdio.h>
int num_digits(int n) { int i,num; while (num != 0){ i = 0; num /= 10; i++;} printf("%d", i); }
int main(void) { int n; scanf("%d", n); num_digits(n); system("PAUSE"); return 0; }
Thanks for the help!
"write a function num_digits(n) that returns the number ofdigits in n. (to determine number of digits, divide it by 10repeatedly.)
this is what I have, but it's not working properly and I knowi have a mistake, just can't figure out where.
#include <stdio.h>
int num_digits(int n) { int i,num; while (num != 0){ i = 0; num /= 10; i++;} printf("%d", i); }
int main(void) { int n; scanf("%d", n); num_digits(n); system("PAUSE"); return 0; }
Thanks for the help! #include <stdio.h>
int num_digits(int n) { int i,num; while (num != 0){ i = 0; num /= 10; i++;} printf("%d", i); }
int main(void) { int n; scanf("%d", n); num_digits(n); system("PAUSE"); return 0; }
Thanks for the help!