#include <stdio.h> #include <stdlib.h> / * Title: Given a positive integer not exceeding 5, and requirements: First, it is seeking few, two, reverse printing out of the digits. * / Int main () { int A, A1, A2, A3, A4, A5; the while ( . 1 ) { the printf ( " Enter a number from 5 within: " ); Scanf ( " % D " , & A ); IF (A <= . 9 ) the printf ( " total number of bits, reverse:% D \ n- " , A); the else IF (A <= 99 ) { A1 = A% 10 ; A2 = A / 10 ; the printf ( " of 2 bits, reverse:% D% D \ n- " , A1, A2);} the else IF (A <= 999 ) { A1 = A% 10 ; A2 = A / 10 % 10 ; A3 = A / 100 ; the printf ( " total of 3 digits, reverse: D%%% D D \ n- " , A1, A2, A3);} the else IF (A <= 9999 ) { A1 = A% 10 ; A2 = A / 10 % 10 ; A3 = A / 100 % 10 ; A4 = A /1000 ; the printf ( " 4-digit, reverse: D%%% D D D% \ n- " , A1, A2, A3, A4);} the else IF (A <= 99999 ) { A1 = A% 10 ; A2 A = / 10 % 10 ; A3 = A / 100 % 10 ; A4 = A / 1000 % 10 ; A5 = A / 10000 ; the printf ( " total of five digits, reverse:% d% d% d% d% d \ n- " , A1, A2, A3, A4, A5);} the else the printf ( " input error, please re-enter \ n- " ); } return 0; }
Method Two
#include <stdio.h> #include <stdlib.h> int main () { int I, L; char A [ . 5 ]; the while ( . 1 ) { the printf ( " Enter a number: " ); for (I = 0 ; I < 100 ; I ++ ) { Scanf ( " % C " , & A [I]); IF (A [I] == ' \ n- ' ) BREAK ;} L = I; the printf ( " total% d bits, reverse output is: " , L); for (i=l-1;i>=0;i--) //a[l] printf("%c",a[i]); printf("\n________________________________\n"); } return 0; }