task1 源代码

 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     {
20         line = rand() % 25;
21         col = rand() % 80;
22         print_text(line, col, text);
23         Sleep(1000);
24     }
25     
26     system("pause");
27     return 0;
28 }
29 
30 
31 void print_spaces(int n)
32 {
33     int i;
34     
35     for(i = 1; i <= n;++i)
36         printf("\n");
37 }
38 
39 void print_blank_lines(int n)
40 {
41     int i;
42     
43     for (i = 1;i <= n;++i)
44          printf("\n");
45 }
46 
47 void print_text(int line, int col, char text[])
48 {
49     print_blank_lines(line - 1);
50     print_spaces(col - 1);
51     printf("%s",text);
52 }

 

task1 截屏

 

task2 源代码

 1 #include <stdio.h>
 2 
 3 long long fac(int n);
 4 
 5 int main()
 6 {
 7     int i, n;
 8     
 9     printf("Enter n: ");
10     scanf("%d",&n);
11     
12     for (i = 1;i <= n;++i)
13     {
14         printf("%d! = %lld\n", i, fac(i));
15     }
16     
17     return 0;
18 }
19 
20 
21 long long fac(int n)
22 {
23     static long long p = 1;
24      p *= n;
25      
26      return p;
27 }
 1 #include <stdio.h>
 2 
 3 int func(int, int);
 4 
 5 int main()
 6 {
 7     int k = 4, m = 1, p1, p2;
 8     
 9     p1 = func(k, m);
10     p2 = func(k, m);
11     printf("%d, %d\n", p1, p2);
12     
13     return 0;
14 }
15 
16 
17 int func(int a, int b)
18 {
19     static int m = 0, i = 2;
20     
21     i += m + 1;
22     m = i + a + b;
23      
24      return m;
25 }

 

task2 截屏

 

 

task3 源代码

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 
 4 long long func(int n);
 5 
 6 int main()
 7 {
 8     int n;
 9     long long f;
10     
11     while (scanf("%d",&n) != EOF)
12     {
13         f = func(n);
14         printf("n = %d, f = %lld\n", n, f);
15     }
16     
17     system("pause");
18     return 0;
19 }
20 
21 
22 long long func(int n)
23 {
24     long long f = 1;
25     
26     if (n == 0)
27         f = 0;
28     else
29         f = func(n-1)*2+1;
30     
31     return f;
32 }

 

task3 截屏

 

 

task4 源代码

 1 #include <stdlib.h>
 2 #include <stdio.h>
 3 
 4 int func(int n, int m);
 5 
 6 int main()
 7 {
 8     int n, m;
 9     
10     while(scanf("%d%d",&n,&m) != EOF)
11           printf("n = %d, m = %d, ans = %d\n", n, m, func(n,m));
12     
13     system("pause");
14     return 0;
15 }
16 
17 
18 int func(int n, int m)
19 {
20     int ans, ans1;
21     
22         if(n < m)
23         {
24             ans1 = 0;
25         }
26         else if ( m == 1)
27         {
28             ans1 = n;
29         }
30         else if( m == 0)
31         {
32             ans1 = 1;
33         }
34         else
35         {
36             ans1 = func(n-1, m)+func(n-1, m-1);
37         }
38     
39     return ans1;
40 }
 1 #include <stdlib.h>
 2 #include <stdio.h>
 3 
 4 int func(int n, int m);
 5 
 6 int main()
 7 {
 8     int n, m;
 9     
10     while(scanf("%d%d",&n,&m) != EOF)
11           printf("n = %d, m = %d, ans = %d\n", n, m, func(n,m));
12     
13     system("pause");
14     return 0;
15 }
16 
17 
18 int func(int n, int m)
19 {
20     int i = 1, j = 1, part1 = 1, part2 = 1, ans;
21     
22     if (n < m){
23     
24     ans = 0;}
25     
26     else if(n >= m){
27     for(i = n-m+1;i <= n;i++)
28     {
29         part1 *= i;
30     }
31     for(j = 1;j <= m;j++)
32     {
33         part2 *= j;
34     }
35     }
36     
37     
38     ans = part1/part2;
39     
40     return ans;
41 }

 

task4 截屏

 

task5 源代码

 

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 
 4 void ta(int n, char from, char temp, char to);
 5 void move(int n, char from, char to);
 6 
 7 static int count = 0;
 8 
 9 int main()
10 {
11     int n;
12     
13     while (scanf("%d",&n) != EOF)
14     {
15         ta(n, 'A', 'B', 'C');
16         printf("%d\n",count);
17         count = 0;
18     }
19     
20     system("pause");
21     return 0;
22 }
23 
24 
25 void ta(int n, char from, char temp, char to)
26 {
27     if( n == 1 )
28     {
29         move(n, from, to);
30     }
31     else
32     {
33         ta(n-1, from, to, temp);
34         move(n, from, to);
35         ta(n-1, temp, from, to);
36     }
37 }
38 
39 void move(int n, char from, char to)
40 {
41     printf("%d: %c --> %c\n", n, from, to);
42     ++count;
43 }

 

task5 截屏

 

 

task6 源代码

 

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 #include <math.h>
 4 #define N 500
 5 
 6 int x[N];
 7 
 8 long func(long s);
 9 
10 int main()
11 {
12     long s, t;
13     
14     printf("Enter a number: ");
15     while (scanf("%ld",&s) != EOF)
16     {
17         t = func(s);
18         printf("New number is: %ld\n\n", t);
19         printf("Enter a number: ");
20     }
21     
22     system("pause");
23     return 0;
24 }
25 
26 
27 long func(long s)
28 {
29     long ans = 0, q;
30     int n = 0, count = 0, m, j = 1, i, ten = 1, p;
31     q = s;
32     
33     do{
34         q /= 10;
35         ++n;
36     }while(q != 0);
37     
38     for(i = 1;i <= n;i++)
39     {
40         m = s%10;
41         if (m%2 != 0)
42         {
43             x[j] = m;
44         
45             for(p = 2; p <= j;p++)
46             {
47                 ten *= 10;
48             }
49         
50             ans += x[j]*ten;
51             ten = 1;
52             j++;
53         }
54         
55         s = s/10;
56     }
57     
58     return ans;
59 }

 

task6 截屏