#include<stdio.h> int func(int n,int m); int main() { int n,m; while(scanf("%d%d",&n,&m)!= EOF) printf("n=%d,m=%d,ans=%d\n",n,m,func(n,m)); return 0; } int func(int n,int m){ if(n<m) return 0; if(m==0||n==m) return 1; return func(n-1,m-1)+func(n-1,m); }
#include<stdio.h> #include<stdlib.h> int hanoi(int n,char x,char y,char z,int*counter) { int move(char,int,char); if(n==1) { move(x,1,z); (*counter)++; } else { hanoi(n-1,x,z,y,counter); move(x,n,z); (*counter)++; hanoi(n-1,y,x,z,counter); } return 0; } int move(char get,int n,char put) { static int k=1; printf("%d:%c-->%c\n",n,get,put); k++; return 0; } int main() { system("color CF"); int hanoi(int,char,char,char,int*); int n,counter; while(scanf("%d",&n)!=EOF) { counter=0; hanoi(n,'A','B','C',&counter); printf("\n一共移动了%d次\n\n",counter); } return 0; }
#include<stdio.h> #include<math.h> long func(long s); int main(){ long s,t; printf("Enter a number:"); while(scanf("%ld",&s) !=EOF){ t=func(s); printf("new number is:%ld\n\n",t); printf("Enter a number"); } return 0; } long func(long s){ long result=0; long multiplier=1; while(s>0){ long digit=s%10; if(digit%2!=0){ result=result+digit*multiplier; multiplier*=10; } s/=10; } return result; }
标签:return,int,counter,long,char,实验,printf From: https://www.cnblogs.com/u329089/p/17807129.html