C Program To Print Individual Digits Of A Number Code Example


Example 1: 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; }

Example 2: 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; }

Comments

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android How Can I Convert A String To A Editable