Write a program using C language to output each bit of a number (multiple methods)
First:
# Include <stdio. h> int main () {int zheng, I; int m = 0; int yu [10]; int count = 0; scanf ("% d", & m ); zheng = m; for (I = 0; I <10; I ++) if (zheng! = 0) {yu [I] = zheng % 10; zheng = zheng/10; count ++ ;}for (I = 0; I <count; I ++) {printf ("% d", yu [I]);} return 0 ;}
Second:
# Include <stdio. h> int main () {int num = 0; int I = 0; int arr [10]; int left = 0; int right = 0; int j = 0; scanf ("% d", & num); while (num) {arr [I] = num % 10; num = num/10; I ++ ;} // reverse order right = I-1 for the elements in arr [4]; while (left <right) {int tmp = arr [left]; arr [left] = arr [right]; arr [right] = tmp; left ++; right --;} // output for (j = 0; j <I; j ++) {printf ("% d", arr [j]);} printf ("\ n"); return 0 ;}
Third: recursive
# Include <stdio. h> void print (int num) // recursion {if (num> = 10) print (num/10); printf ("% d", num % 10 );} int main () {int num = 10; scanf ("% d", & num); print (num); return 0 ;}