--c++ implementation of reverse inversion algorithm

Source: Internet
Author: User

Reverse Inversion algorithm

1#include <iostream>2 3 using namespacestd;4 //function of Exchange5 voidReplaced (int&a,int&b) {6     intt =A;7A =b;8b =T;9 }Ten //reversal One voidReversed (intA[],intlength) { A     intleft =0; -     intright = length-1; -      while(Left <Right ) { the replaced (A[left], a[right]); -left++; -right--; -     } + } - voidOutputintA[],intlength) + { A      for(inti =0; i<length; i++) { atcout << A[i] <<" "; -     } - } - intMain () - { -     intA[] = {1,2,3,4,5,6,7,8,9}; inOutput (A,9); -cout <<Endl; toReversed (A,9); +Output (A,9); -}

Fibonacci sequence

1#include <iostream>2 3 using namespacestd;4 5 //Fibonacci Sequence6 intQiebona (inta)7 {8     //You can also use the IF statement9     Switch(a) {Ten          Case 1: One          Case 2: A             returnA; -              Break; -              the         default: -             returnQiebona (A-1) +qiebona (A-2); -              Break; -     } + } - intMain () + { A     //Verifying the Fibonacci function atcout << Qiebona (1) <<Endl; -     //then print the Fibonacci sequence of the first n numbers. -      for(inti =1; I <=Ten; i++) { -cout << Qiebona (i) <<" "; -     } -     return 0; in}

--c++ implementation of reverse inversion algorithm

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.