实验一
1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<time.h> 4 #include<windows.h> 5 #define N 80 6 7 void print_text(int line,int col,char text[]); 8 void print_spaces(int n); 9 void print_blank_lines(int n); 10 11 int main(){ 12 int line,col,i; 13 char text[N]="hi,november"; 14 15 srand(time(0)); 16 for(i=1;i<=10;++i) 17 { 18 line=rand()%25; 19 col= rand() % 80; 20 print_text(line, col, text); 21 Sleep(1000); 22 } 23 return 0; 24 } 25 void print_spaces(int n) { 26 int i; 27 for(i = 1; i <= n; ++i) 28 printf(" "); 29 } 30 void print_blank_lines(int n) { 31 int i; 32 33 for(i = 1; i <= n; ++i) 34 printf("\n"); 35 } 36 void print_text(int line, int col, char text[]) { 37 print_blank_lines(line-1); 38 print_spaces(col-1); 39 printf("%s", text); 40 }
实验一截图
实验二
1 #include<stdio.h> 2 long long fac(int n); 3 4 int main() 5 { 6 int i,n; 7 8 printf("Enter n:"); 9 scanf("%d",&n); 10 for(i=1;i<=n;++i) 11 printf("%d!=%lld\n",i,fac(i)); 12 13 return 0; 14 } 15 long long fac(int n){ 16 static long long p=1; 17 printf("p=%lld\n",p); 18 p=p*n; 19 return p; 20 }
1 #include<stdio.h> 2 int func(int,int); 3 4 int main(){ 5 int k=4,m=1,p1,p2; 6 7 p1=func(k,m); 8 p2=func(k,m); 9 printf("%d %d\n",p1,p2); 10 return 0; 11 } 12 13 int func(int a,int b){ 14 static int m=0,i=2; 15 i+=m+1; 16 m=i+a+b; 17 18 return m; 19 }
实验二截图
实验三
1 #include<stdio.h> 2 long long func(int n); 3 4 int main(){ 5 int n; 6 long long f; 7 8 while(scanf("%d",&n)!=EOF) 9 { 10 f=func(n); 11 printf("n=%d,f=%lld\n",n,f); 12 } 13 return 0; 14 } 15 16 long long func(int n){ 17 if(n==1) 18 return 1; 19 else 20 return 2*func(n-1)+1; 21 }
实验三截图
实验四
1 #include<stdio.h> 2 int func(int n,int m); 3 4 int main(){ 5 int n,m; 6 while(scanf("%d %d",&n,&m)!=EOF) 7 printf("n=%d,m=%d,ans=%d\n",n,m,func(n,m)); 8 9 return 0; 10 } 11 12 int func(int n,int m){ 13 if(n==m||m==0) 14 return 1; 15 if(n<m) 16 return 0; 17 else 18 return func(n-1,m)+func(n-1,m-1); 19 }
1 #include<stdio.h> 2 int func(int n,int m); 3 4 int main() 5 { 6 int n,m; 7 while(scanf("%d %d",&n,&m)!=EOF) 8 printf("n=%d,m=%d,ans=%d\n",n,m,func(n,m)); 9 10 return 0; 11 } 12 13 int func(int n,int m) { 14 15 int a=1,b=1,c=1,i=1; 16 if(n>m){ 17 18 for(i=1;i<=n;++i) { 19 a*=i; 20 } 21 for(i=1;i<=m;++i) 22 { 23 b*=i; 24 }for(i=1;i<=n-m;++i) 25 { 26 c*=i; 27 } 28 return a/(b*c); 29 } 30 31 32 if(n<m) 33 return 0; 34 35 if(n==m||m==0) 36 return 1; 37 38 }
实验四截图
实验五
1 #include<stdio.h> 2 3 void hanoi(unsigned int n,char from,char temp,char to,int count); 4 void moveplate(unsigned int n,char from,char to); 5 6 int main(){ 7 unsigned int n; 8 int count=0; 9 while(scanf("%u",&n)!=EOF){ 10 hanoi(n,'A','B','C',count); 11 printf("cishu:",count); 12 } 13 return 0; 14 } 15 16 void hanoi(unsigned int n,char from,char temp,char to,int count){ 17 if(n==1){ 18 moveplate(n,from,to); 19 count++; 20 } 21 else 22 { 23 hanoi(n-1,from,to,temp,count); 24 count++; 25 moveplate(n,from,to); 26 hanoi(n-1,temp,from,to,count); 27 count++; 28 } 29 } 30 31 void moveplate(unsigned int n,char from,char to) 32 { 33 printf("%u:%c->%c\n",n,from,to);
}
实验五截图
实验六
1 #include<stdio.h> 2 #include<math.h> 3 long func(long s); 4 5 int main(){ 6 long s,k; 7 8 printf("Enter a number:"); 9 while(scanf("%ld",&s)!=EOF){ 10 k=func(s); 11 printf("new number is:%ld\n\t",k); 12 printf("Enter a number:"); 13 14 } 15 return 0; 16 } 17 long func(long s) 18 { 19 int r=0; 20 int k=0; 21 while(s!=0){ 22 if(s%2==0) 23 { 24 s=s/10; 25 } 26 else 27 { 28 r=r*10+s%10; 29 s=s/10; 30 } 31 } 32 while(r!=0) 33 { 34 k=k*10+r%10; 35 r=r/10; 36 } 37 return k; 38 39 }
实验六截图
标签:10,int,long,char,实验,func,include From: https://www.cnblogs.com/cwc6276/p/17798869.html