Some recursive programs

Source: Internet
Author: User

Code One:

#include <iostream>using namespace std;void ten_to_two (int num); int main () {int num=10;ten_to_two (num); return 0;} void ten_to_two (int num) {if (num!=0) {int m=num%2;num=num/2;ten_to_two (num); cout<<m;}}
Code two: (Binary recursive algorithm)

#include <iostream>using namespace Std;int leihe (int); float Multiply (int); int main () {int num=4;cout<< Leihe (+) <<endl;cout<< "n!=" <<multiply (num) <<endl;return 0;} int Leihe (int num)//cumulative recursive {if (num!=0) return Leihe (num-1) +num;  
Code three: (Decomposition of integer recursive algorithm)

/* Decompose the number */#include <iostream>using namespace std;void resolve (int n); int main () {int m=0;cin>>m;resolve (m); return 0;} void Resolve (int n) {if (n!=0) {int m=n%10;n=n/10;resolve (n); Cout<<m<<endl;}}

Code four: (Decomposition of mass factor recursive algorithm)

#include <iostream>using namespace std;void prime_number (int num, int n) {    if (num >=n)    {while        (num % n)  n++;//Find a mass factor        num/= n;//divide this factorization        if (num>=n)        cout<<n<< "*";//print this factorization else cout <<n;         Prime_number (num,n);    }    else    Cout<<endl;} int main () {    int n,m;    cin>>n>>m;    for (int i=n;i<=m;i++) {    cout<<i<< "=";    Prime_number (i,2);    }    return 0;}

(End of full text)

Some recursive programs

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.