c how many digits has a number
digits = (number == 0) ? 1 : (log10(number) + 1);
//or
while (number > 0)
{
number /= 10;
digits++;
}
//see: https://ideone.com/P1h8Ne
c how many digits has a number
digits = (number == 0) ? 1 : (log10(number) + 1);
//or
while (number > 0)
{
number /= 10;
digits++;
}
//see: https://ideone.com/P1h8Ne
print digits of a number in c
#include <stdio.h>
int main(){
int num = 1024;
while(num != 0){
int digit = num % 10;
num = num / 10;
printf("%d\n", digit);
}
return 0;
}
print digits of a number in c
#include <stdio.h>
int printDigits(int n){
int digit;
if(n < 10){//caso base
digit = n;
printf("%d\n", digit);
}else{
digit = printDigits(n/10);
digit = printDigits(n%10);
}
return digit;
}
int main(){
int num = 3467678;
printDigits(num);
return 0;
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us