标签:
代码一:
#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; } }代码二:(二进制的递归算法)
#include <iostream> using namespace std; int leihe(int); float Multiply(int); int main() { int num=4; cout<<leihe(100)<<endl; cout<<"n!="<<Multiply(num)<<endl; return 0; } int leihe(int num)//累加的递归 { if(num!=0) return leihe(num-1)+num; } float Multiply(int num) { //if(num<0) cout<<"错误"; if(num==1||num==0) return 1; else return (Multiply(num-1)*num); }代码三:(分解整数递归算法)
/*分解数字*/ #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; } }
#include <iostream> using namespace std; void prime_number(int num, int n) { if(num >=n) { while(num % n) n++; //找到一个质因数 num /= n; //除以这个质因数 if(num>=n) cout<<n<<"*"; //打印这个质因数 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; }
(全文完)
标签:
原文地址:http://blog.csdn.net/confidence_surmount/article/details/45065121