tesk1
代码
#include<time.h> #include<windows.h> #define N 80 void print_text(int line,int col,char text[]); void print_spaces(int n); void print_blank_lines(int n); int main() { int line,col,i; char text[N]="hi,November~"; srand(time(0)); for(i=0;i<=10;i++){ line=rand()%25; col=rand()%80; print_text(line,col,text); Sleep(1000); } return 0; } void print_spaces(int n){ int i; for(i=1;i<=n;++i){ printf(" "); } } void print_blank_lines(int n){ int i; for(i=1;i<=n;++i){ printf("\n"); } } void print_text(int line,int col,char text[]){ print_blank_lines(line-1); print_spaces(col-1); printf("%s",text); }
运行结果
功能:随机位置生成字符
test2.1
代码
#include<stdio.h> long long fac(int n); int main() { int i,n; printf("Enter n:"); scanf("%d",&n); for(i=1;i<=n;++i){ printf("%d!=%lld\n",i,fac(i)); } return 0; } long long fac(int n) { static long long p=1; p=p*n; printf("p=%lld\n",p); return p; }
运行结果
test2.2
代码
#include<stdio.h> int func(int,int); int main() { int k=4,m=1,p1,p2; p1=func(k,m); p2=func(k,m); printf("%d,%d\n",p1,p2); return 0; } int func(int a,int b) { static int m=0,i=2; i+=m+1; m=i+a+b; return m; }
运行结果
test3
代码
#include<stdio.h> long long func(int n); int main() { int n; long long f; while(scanf("%d",&n)!=EOF){ f=func(n); printf("n=%d,f=%lld\n",n,f); } return 0; } long long func(int n) { if(n==1){ return 1; }else{ long long f; n--; f=(func(n)+1)*2-1; } }
运行结果
test4
代码
#include<stdio.h> int func(int n,int m); int main() { int n,m,ans; 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(m>n){ return 0; }else if(m==0||m==n){ return 1; }else if(m==1){ return n; }else{ int p,q,s; n--; p=func(n,m); m--; q=func(n,m); s=p+q; } }
#include<stdio.h> int func(int n,int m); int main() { int n,m,ans; 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; }else if(n==m||m==0){ return 1; }else if(m==1){ return m; }else{ int i,j,p=1,q=1,s=1; for(i=1;i<=m;i++){ p*=i; } for(j=n-m+1;j<=n;j++){ q*=j; } s=q/p; return s; } }
运行结果
test5
代码
#include<stdio.h> void hanoi(int n,char from,char temp,char to); void moveplate(int n,char from,char to); int j; int main() { int n; while(scanf("%d",&n)!=EOF){ hanoi(n,'A','B','C'); printf("一共移动了%d次\n",j); j=0; } return 0; } void hanoi(int n,char from,char temp,char to) { if(n==1){ moveplate(n,from,to); }else{ hanoi(n-1,from,to,temp); moveplate(n,from,temp); hanoi(n-1,temp,from,to); } } void moveplate(int n,char from,char to) { printf("%d:%c-->%c\n",n,from,to); j++; }
运行结果
test6
代码
#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:%d\n\n",t); printf("Enter a number:"); } return 0; } long func(long s) { int k=0,m=0,n=1; while(s>=10){ k=s%10; if(k%2!=0){ m+=k*n; n*=10; } s/=10; } if(s<10){ if(s%2!=0){ return n*s+m; }else{ return m; } } }
运行结果
test7
代码
#include<stdio.h> #define N 100 int main() { int i; for(i=1;i<=N;i++){ int m=0; int n=0; int t=1,c; m=i*i; n=i*i*i; int j=0,a,b; int x[N]; while(m>0){ x[j]=m%10; j++; m/=10; } while(n>0){ x[j]=n%10; j++; n/=10; } if(j!=10){ continue; } else{ for(a=0;a<9;a++){ for(b=a+1;b<=9;b++){ if(x[a]==x[b]){ t=0; break; } } } if(t==1){ printf("%d\n",i); break; } } } return 0; }
运行结果
标签:return,int,long,char,实验,func,include From: https://www.cnblogs.com/iamqy/p/17798140.html