age(n) int n; { int c; if(n==1) c=10; else c=age(n-1)+2; return(c); } main() { printf("%d",age(5)); } ============================================================== 【程序29】
題目:給一個不多于5位的正整數,要求:一、求它是幾位數,二、逆序打印出各位數字。
1. 程序分析:學會分解出每一位數,如下解釋:(這里是一種簡單的算法,師專數002班趙鑫提供)
2.程序源代碼:
main( ) { long a,b,c,d,e,x; scanf("%ld",&x); a=x/10000;/*分解出萬位*/ b=x%10000/1000;/*分解出千位*/ c=x%1000/100;/*分解出百位*/ d=x%100/10;/*分解出十位*/ e=x%10;/*分解出個位*/ if (a!=0) printf("there are 5, %ld %ld %ld %ld %ld/n",e,d,c,b,a); else if (b!=0) printf("there are 4, %ld %ld %ld %ld/n",e,d,c,b); else if (c!=0) printf(" there are 3,%ld %ld %ld/n",e,d,c); else if (d!=0) printf("there are 2, %ld %ld/n",e,d); else if (e!=0) printf(" there are 1,%ld/n",e); } ============================================================== 【程序30】
main( ) { long ge,shi,qian,wan,x; scanf("%ld",&x); wan=x/10000; qian=x%10000/1000; shi=x%100/10; ge=x%10; if (ge==wan&&shi==qian)/*個位等于萬位并且十位等于千位*/ printf("this number is a huiwen/n"); else printf("this number is not a huiwen/n"); }