实验1
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 { 13 int line, col, i; 14 char text[N] = "hi,November~"; 15 16 srand(time(0));//以当前系统时间作为随机种子 17 18 for(i = 1;i<=10;++i){ 19 line = rand() % 25; 20 col = rand() % 80; 21 print_text(line, col, text); 22 Sleep(1000);//暂停1000ms 23 } 24 return 0; 25 } 26 27 //打印n个空格 28 void print_spaces(int n){ 29 int i; 30 31 for(i = 1;i<=n;++i) 32 printf(" "); 33 } 34 35 //打印n行空白行 36 void print_blank_lines(int n){ 37 int i; 38 for(i = 1;i<=n;++i) 39 printf("\n"); 40 } 41 42 //在第line行第col列打印一段文本 43 void print_text(int line, int col, char text[]){ 44 print_blank_lines(line-1); //打印line-1行空行 45 print_spaces(col-1); //打印col-1列空格 46 printf("%s",text); //在第line行col列输出text中字符串 47 }
实验2.1
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 16 long long fac(int n){ 17 static long long p=1; 18 printf("p = %lld\n",p); 19 p=p*n; 20 21 return p; 22 }
实验2.2
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 11 return 0; 12 } 13 14 int func(int a,int b){ 15 static int m =0, i= 2; 16 17 i +=m +1; 18 m = i + a + b; 19 20 return m; 21 }
实验3
1 #include<stdio.h> 2 3 long long func(int n); 4 5 int main() 6 { 7 int n; 8 long long f; 9 10 while(scanf("%d",&n)!=EOF){ 11 f= func(n); 12 printf("n = %d, f = %lld\n",n , f); 13 } 14 return 0; 15 } 16 17 long long func(int n){ 18 if(n==1) 19 return 1; 20 21 return (func(n-1)+1)*2-1; 22 }
标签:main,return,int,long,实验,func,include From: https://www.cnblogs.com/u3291193/p/17798295.html