C practical exercise topic 29

Time:2020-9-23

Title:To give a positive integer with no more than 5 digits, the requirements are as follows: 1. Find the number of digits; 2. Print out the numbers in reverse order.

Program analysis:Learn to break down each digit, as explained below.

example:

#include 
  
 int main( )
 {
     long a,b,c,d,e,x;
     Printf ("please input 5 digits)";
     scanf("%ld",&x);
     A = x / 10000; / * decomposes ten thousand bits*/
     B = x% 10000 / 1000; / * decomposed into thousands*/
     C = x% 1000 / 100; / * decomposes into hundreds*/
     D = x% 100 / 10; / * decomposes into ten bits*/
     E = x% 10; / * decomposes into bits*/
     if (a!=0){
         Printf ("is 5 digits, reverse order is: LD% LD% LD% LD% LD% LD, e, D, C, B, a)";
     } else if(b!=0) {
          Printf ("is 4 digits, reverse order is: LD% LD% LD% LD / N", e, D, C, b);
     } else if(c!=0) {
          Printf ("is 3 digits, reverse order is: LD% LD% LD / N", e, D, c);
     } else if(d!=0) {
          Printf ("is 2 digits, reverse order is% LD% LD / N", e, d);
     } else if(e!=0) {
          Printf ("is 1 digit, reverse order is% LD / N", e);
     }
 }

The output results of the above examples are as follows:

Please input 5 digits: 12345
The reverse order is 543 21

Thank you for your reading, please feel with your heart! Hope to help you who love learning!! Sharing is also a kind of happiness!!! Please relay…

Click to view the original text, thank you!

Recommended Today

Interviewer: young man, what do you think of the principle of distributed system

1 Concept 1.1 model 1.2 copies 1.3 indicators for measuring distributed systems 2. Principle of distributed system 2.1 data distribution 2.2 basic copy agreement 2.3 lease mechanism 2.4 quorum mechanism 2.5 log technology 2.6 two phase submission protocol 2.7 MVCC 2.8 Paxos protocol 2.9 CAP 1 Concept 1.1 model node In a specific project, a […]