print digits of a number in c

Solutions on MaxInterview for print digits of a number in c by the best coders in the world

showing results for - "print digits of a number in c"
Ariana
23 Mar 2018
1digits = (number == 0) ? 1 : (log10(number) + 1);
2//or
3while (number > 0)
4{
5	number /= 10;
6	digits++;
7}
8//see: https://ideone.com/P1h8Ne
Josefina
23 Apr 2016
1#include <stdio.h>
2
3int main(){
4    int num = 1024;
5
6    while(num != 0){
7        int digit = num % 10;
8        num = num / 10;
9        printf("%d\n", digit);
10    }
11  
12    return 0;
13}
Juan José
22 Oct 2018
1#include <stdio.h>
2
3int printDigits(int n){
4  int digit;
5  
6  if(n < 10){//caso base
7      digit = n;
8      printf("%d\n", digit);
9    }else{
10      digit = printDigits(n/10);
11      digit = printDigits(n%10);
12    }
13
14    return digit;
15}
16
17int main(){
18    int num = 3467678;
19
20    printDigits(num);
21
22    return 0;
23}
similar questions
queries leading to this page
print digits of a number in c