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