资源描述:
《C语言数据结构编程题资料》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、1、将一整数逆序后放入一数组中(要求递归实现)voidconvert(int*result,intn){if(n>=10)convert(result+1,n/10);*result=n%10;}intmain(intargc,char*argv[]){intn=123456789,result[20]={};convert(result,n);printf("%d:",n);for(inti=0;i<9;i++)printf("%d",result[i]);}2、求高于平均分的学生学号及成绩(学号和成绩人工输入)doublefind(inttotal,intn){in
2、tnumber,score,average;scanf("%d",&number);if(number!=0){scanf("%d",&score);average=find(total+score,n+1);if(score>=average)printf("%d:%d",number,score);returnaverage;}else{printf("Average=%d",total/n);returntotal/n;}}intmain(intargc,char*argv[]){find(0,0);}3、递归实现回文判断(如:abcdedbca就是回文,
3、判断一个面试者对递归理解的简单程序)intfind(char*str,intn){if(n<=1)return1;elseif(str[0]==str[n-1])returnfind(str+1,n-2);elsereturn0;}intmain(intargc,char*argv[]){char*str="abcdedcba";printf("%s:%s",str,find(str,strlen(str))?"Yes":"No");}4、组合问题(从M个不同字符中任取N个字符的所有组合)voidfind(char*source,char*result,intn){
4、if(n==1){while(*source)printf("%s%c",result,*source++);}else{inti,j;for(i=0;source[i]!=0;i++);for(j=0;result[j]!=0;j++);for(;i>=n;i--){result[j]=*source++;result[j+1]=' ';find(source,result,n-1);}}}intmain(intargc,char*argv[]){intconstn=3;char*source="ABCDE",result[n+1]={0};if(n>0&&st
5、rlen(source)>0&&n<=strlen(source))find(source,result,3);}5、分解成质因数(如435234=251*17*17*3*2,据说是华为笔试题)voidprim(intm,intn){if(m>n){while(m%n!=0)n++;m/=n;prim(m,n);printf("%d*",n);}}intmain(intargc,char*argv[]){intn=435234;printf("%d=",n);prim(n,2);}6、寻找迷宫的一条出路,o:通路;X:障碍。(大家经常谈到的一个小算法题)#defineM
6、AX_SIZE8intH[4]={0,1,0,-1};intV[4]={-1,0,1,0};charMaze[MAX_SIZE][MAX_SIZE]={{'X','X','X','X','X','X','X','X'},{'o','o','o','o','o','X','X','X'},{'X','o','X','X','o','o','o','X'},{'X','o','X','X','o','X','X','o'},{'X','o','X','X','X','X','X','X'},{'X','o','X','X','o','o','o','X'},{'X','o'
7、,'o','o','o','X','o','o'},{'X','X','X','X','X','X','X','X'}};voidFindPath(intX,intY){if(X==MAX_SIZE
8、
9、Y==MAX_SIZE){for(inti=0;i=0&&Y>=0&&Y