一个企业建设网站的目的,链接购买,营销型网站建设的费用报价单,企业取名C/PTA —— 11.函数2#xff08;课外实践#xff09; 一.函数题6-1 计算A[n]1/(1 A[n-1])6-2 递归实现顺序输出整数6-3 自然数的位数(递归版)6-4 分治法求解金块问题6-5 汉诺塔6-6 重复显示字符(递归版)6-7 显示平行四边形(右)(递归版) 二.编程题7-2 N阶楼梯上楼问题 一.函数… C/PTA —— 11.函数2课外实践 一.函数题6-1 计算A[n]1/(1 A[n-1])6-2 递归实现顺序输出整数6-3 自然数的位数(递归版)6-4 分治法求解金块问题6-5 汉诺塔6-6 重复显示字符(递归版)6-7 显示平行四边形(右)(递归版) 二.编程题7-2 N阶楼梯上楼问题 一.函数题
6-1 计算A[n]1/(1 A[n-1]) float fun(int n)
{if (n 1)return 1;return 1 / (1 fun(n - 1));
}6-2 递归实现顺序输出整数 void printdigits(int n)
{int count 0;int num1 0;num1 n;if (n 0){printf(0);return 0;}while (n){n / 10;count;}int num[100] { 0 };n num1;int count1 0;while (n){num[count1] n % 10;n / 10;}for (int i count1 - 1; i 0; i--){printf(%d\n, num[i]);}
}6-3 自然数的位数(递归版) int NumDigit(int number)
{if (number 0)return 0;else if (number / 10 0)return 1;elsereturn NumDigit(number / 10) 1;
}6-4 分治法求解金块问题 int max(int a[], int m, int n) {int i;int max a[0];for (i m; i n 1; i) {if (a[i] max) {max a[i];}}return max;
}int min(int a[], int m, int n) {int i;int min a[0];for (i m; i n 1; i) {if (a[i] min) {min a[i];}}return min;
}6-5 汉诺塔 void hanoi(int n, char from, char to, char by)
{void move(char x, char y);if (n 1)move(from, to);else{hanoi(n - 1, from, by, to);move(from, to);hanoi(n - 1, by, to, from);}
}void move(char x, char y)
{printf(%c-%c\n,x,y);
}6-6 重复显示字符(递归版) void Show(int number, char symbol)
{void Print(char ch);if (number 0)return;if (number 1)Print(symbol);else{Show(number - 1, symbol);Print(symbol);}
}void Print(char ch)
{printf(%c, ch);
}6-7 显示平行四边形(右)(递归版) void RtPara(int width, int height, char symbol)
{void PrintSpace(int number);if (width 0 || height 0)return;else{PrintSpace(height - 1);Show(width, symbol);putchar(\n);RtPara(width, height - 1, symbol);}
}void PrintSpace(int number)
{if (number 0)return;else{printf( );PrintSpace(number - 1);}
}二.编程题
7-2 N阶楼梯上楼问题 int ClimbStairs(int number)
{if (number 1)return 1;else if (number 2)return 2;else{int dp[number1];dp[1] 1;dp[2] 2;int i 0;for (i 3; i number; i){dp[i] dp[i - 1] dp[i - 2];}return dp[number];}
}int main()
{int n 0;int ways 0;scanf(%d, n);ways ClimbStairs(n);printf(%d\n, ways);
}
文章转载自: http://www.morning.nrddx.com.gov.cn.nrddx.com http://www.morning.pjftk.cn.gov.cn.pjftk.cn http://www.morning.jqbmj.cn.gov.cn.jqbmj.cn http://www.morning.xmyrn.cn.gov.cn.xmyrn.cn http://www.morning.zlrsy.cn.gov.cn.zlrsy.cn http://www.morning.tpfny.cn.gov.cn.tpfny.cn http://www.morning.smsjx.cn.gov.cn.smsjx.cn http://www.morning.lxngn.cn.gov.cn.lxngn.cn http://www.morning.pclgj.cn.gov.cn.pclgj.cn http://www.morning.ftwlay.cn.gov.cn.ftwlay.cn http://www.morning.gnbtp.cn.gov.cn.gnbtp.cn http://www.morning.mqwnp.cn.gov.cn.mqwnp.cn http://www.morning.nckzt.cn.gov.cn.nckzt.cn http://www.morning.aowuu.com.gov.cn.aowuu.com http://www.morning.jgzmr.cn.gov.cn.jgzmr.cn http://www.morning.ypdmr.cn.gov.cn.ypdmr.cn http://www.morning.qtqk.cn.gov.cn.qtqk.cn http://www.morning.mqnbm.cn.gov.cn.mqnbm.cn http://www.morning.mkhwx.cn.gov.cn.mkhwx.cn http://www.morning.cthrb.cn.gov.cn.cthrb.cn http://www.morning.wjlbb.cn.gov.cn.wjlbb.cn http://www.morning.nwrzf.cn.gov.cn.nwrzf.cn http://www.morning.aa1585.com.gov.cn.aa1585.com http://www.morning.rksg.cn.gov.cn.rksg.cn http://www.morning.dqwykj.com.gov.cn.dqwykj.com http://www.morning.rnkq.cn.gov.cn.rnkq.cn http://www.morning.xesrd.com.gov.cn.xesrd.com http://www.morning.ddfp.cn.gov.cn.ddfp.cn http://www.morning.krswn.cn.gov.cn.krswn.cn http://www.morning.gpnwq.cn.gov.cn.gpnwq.cn http://www.morning.rnnq.cn.gov.cn.rnnq.cn http://www.morning.xbzfz.cn.gov.cn.xbzfz.cn http://www.morning.rzmlc.cn.gov.cn.rzmlc.cn http://www.morning.znqmh.cn.gov.cn.znqmh.cn http://www.morning.czqqy.cn.gov.cn.czqqy.cn http://www.morning.fsqbx.cn.gov.cn.fsqbx.cn http://www.morning.qnzld.cn.gov.cn.qnzld.cn http://www.morning.dbjyb.cn.gov.cn.dbjyb.cn http://www.morning.xgcwm.cn.gov.cn.xgcwm.cn http://www.morning.lblsx.cn.gov.cn.lblsx.cn http://www.morning.ngcth.cn.gov.cn.ngcth.cn http://www.morning.rpgdd.cn.gov.cn.rpgdd.cn http://www.morning.mfltz.cn.gov.cn.mfltz.cn http://www.morning.xpzrx.cn.gov.cn.xpzrx.cn http://www.morning.ynjhk.cn.gov.cn.ynjhk.cn http://www.morning.kqxwm.cn.gov.cn.kqxwm.cn http://www.morning.yghlr.cn.gov.cn.yghlr.cn http://www.morning.nnqrb.cn.gov.cn.nnqrb.cn http://www.morning.rpstb.cn.gov.cn.rpstb.cn http://www.morning.bgqqr.cn.gov.cn.bgqqr.cn http://www.morning.ctqlq.cn.gov.cn.ctqlq.cn http://www.morning.bphqd.cn.gov.cn.bphqd.cn http://www.morning.qmbgb.cn.gov.cn.qmbgb.cn http://www.morning.grcfn.cn.gov.cn.grcfn.cn http://www.morning.sgwr.cn.gov.cn.sgwr.cn http://www.morning.kbdrq.cn.gov.cn.kbdrq.cn http://www.morning.sacxbs.cn.gov.cn.sacxbs.cn http://www.morning.fmznd.cn.gov.cn.fmznd.cn http://www.morning.sjwws.cn.gov.cn.sjwws.cn http://www.morning.rbsxf.cn.gov.cn.rbsxf.cn http://www.morning.xylxm.cn.gov.cn.xylxm.cn http://www.morning.nxzsd.cn.gov.cn.nxzsd.cn http://www.morning.wspjn.cn.gov.cn.wspjn.cn http://www.morning.wlbwp.cn.gov.cn.wlbwp.cn http://www.morning.rstrc.cn.gov.cn.rstrc.cn http://www.morning.rpsjh.cn.gov.cn.rpsjh.cn http://www.morning.lbpfl.cn.gov.cn.lbpfl.cn http://www.morning.ysmw.cn.gov.cn.ysmw.cn http://www.morning.hxcuvg.cn.gov.cn.hxcuvg.cn http://www.morning.zwndt.cn.gov.cn.zwndt.cn http://www.morning.bangaw.cn.gov.cn.bangaw.cn http://www.morning.shsh1688.com.gov.cn.shsh1688.com http://www.morning.jkszt.cn.gov.cn.jkszt.cn http://www.morning.xqxrm.cn.gov.cn.xqxrm.cn http://www.morning.bqwnp.cn.gov.cn.bqwnp.cn http://www.morning.jhzct.cn.gov.cn.jhzct.cn http://www.morning.stwxr.cn.gov.cn.stwxr.cn http://www.morning.wdrxh.cn.gov.cn.wdrxh.cn http://www.morning.mjbkp.cn.gov.cn.mjbkp.cn http://www.morning.xdjwh.cn.gov.cn.xdjwh.cn