当前位置:网站首页>Integer reverse output of C language test question 166

Integer reverse output of C language test question 166

2022-06-09 22:18:00 Maserati

Personal home page : Personal home page
Series column :C Language test questions 200 example
Recommend a brush algorithm 、 written examination 、 Face the 、 Nada Corporation offer Artifact Click jump to enter the website
Author's brief introduction : Hello everyone , I'm Maserati ,CSDN Blogger ( Ranking of the whole station Top 50), Alibaba cloud blog expert 、51CTO Blogger 、 Huawei cloud sharing expert

1、 subject

subject : Store an integer entered from the keyboard into an array , The integer is output in the reverse order of the array through the operation of the program , Use recursive methods to solve problems .

analysis :
Design functions to store data in reverse order , Set the address where the formal parameter array receives the argument array , To store every bit of data . The function body solves the problem recursively , So consider the conditions for recursion . for example , The data n Store in array s in , if n It's one digit. , Then store n To array ; if n Not a single digit , Then store n/10 To array .

The difficulty in solving the problem lies in finding the storage address of the data , By constantly taking remainder and dividing 10 Get every bit of data . In order to store data in reverse order , Every division 10 When , At the same time, the address of the array where the data is stored is moved back , The first digit thus obtained is stored in the last digit of the array …… By moving forward one by one , Recursive regression , Realize the storage of the whole data . By function convert() Realize the reverse conversion of numbers in the string .




原网站

版权声明
本文为[Maserati]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/160/202206092135276180.html