C-output each node in reverse/forward order.

Source: Internet
Author: User
1 # include <stdio. h> 2 # include <math. h> 3 4/* 5: Judge the number of digits of a positive integer, and output Their digits in the forward and backward order. 6 */7 8 int 9 invert (INT); 10 11 void12 Order (INT, INT); 13 14 int 15 main (void) {16 int n = 56789; 17 printf ("Original: % d \ n", n); 18 int bitcont = invert (n); 19 printf ("\ nbits: % d \ n", bitcont ); 20 order (n, bitcont); 21 return 0; 22} 23 24 // output each bit in reverse order and record the number of digits. 25 int 26 invert (int n) {27 int bitcount = 0; // number of records. 28 do 29 {30 + + bitcount; 31 printf ("% d", N % 10); // output each bit in reverse order. 32 N/= 10; 33} while (n); // The condition for termination is "N is 0 ". 34 return bitcount; 35} 36 37 // output each digit in positive order. 38 void39 Order (int n, int bitcount) {40 int TMP = 0; // storage level to be subtracted, for example, when n is "1234", the storage "1000 "; when N is "234", the storage is "100 ". 41 int h = 0; // store the highest bit. 42 while (n) {43 TMP = (INT) Pow (double) 10, -- bitcount); 44 h = N/tmp; 45 printf ("% d ", h); 46 N-= H * TMP; 47} 48}

 

Output:

Original: 567899 8 7 6 5 bits: 55 6 7 8 9 press any key to continue...

 

C-output each node in reverse/forward order.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.