Recursively returns an integer in reverse order.

Source: Internet
Author: User
// Reverse an integer int # include <iostream> using namespace STD; // reference void intrev (int nsrc, Int & NDEs) {If (0 = NSRC) {return;} else {NDEs = NDEs * 10 + NSRC % 10; intrev (NSRC/10, NDEs );}} // use the local static variable to initialize the int intrev2 (INT num) {static int ret = 0; If (0 = num) {return ret ;} else {ret = RET * 10 + num % 10; return intrev2 (Num/10) ;}} int main (INT argc, char * argv []) {int nint = 256425; int Nout = 0; // firtintrev (nint, Nout); cout <"int number:" <nint <", reverse:" <Nout <Endl; // secondnint = 456624; cout <"int number:" <nint <", reverse:" <intrev2 (nint) <Endl; return 0 ;}

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: 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.