首页 > 其他分享 >实验3

实验3

时间:2022-11-06 17:25:05浏览次数:47  
标签:return int long char 实验 func include

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 #include <time.h>
 4 #include <windows.h>
 5 #define N 80
 6 void print_text(int line, int col, char text[]); 
 7 void print_spaces(int n); 
 8 void print_blank_lines(int n); 
 9 int main() {
10 int line, col, i;
11 char text[N] = "hi, November~";
12 srand(time(0));
13 for(i = 1; i <= 10; ++i) {
14 line = rand() % 25;
15 col = rand() % 80;
16 print_text(line, col, text);
17 Sleep(1000); 
18 }
19 return 0;
20 }
21 
22 void print_spaces(int n) {
23 
24 int i;
25 for(i = 1; i <= n; ++i)
26 printf(" ");
27 }
28 
29 void print_blank_lines(int n) {
30 int i;
31 for(i = 1; i <= n; ++i)
32 printf("\n");
33 }
34 
35 void print_text(int line, int col, char text[]) {
36 print_blank_lines(line-1);
37 print_spaces(col-1); 
38 printf("%s", text); 
39 }

 

 

 

 1 #include <stdio.h>
 2 long long fac(int n); 
 3 int main() {
 4 int i, n;
 5 printf("Enter n: ");
 6 scanf("%d", &n);
 7 for (i = 1; i <= n; ++i)
 8 printf("%d! = %lld\n", i, fac(i));
 9 return 0;
10 }
11 long long fac(int n) {
12 static long long p = 1;
13 p = p * n;
14 return p;
15 }

 

 

 1 #include <stdio.h>
 2 int func(int, int);
 3 int main() {
 4 int k = 4, m = 1, p1, p2;
 5 p1 = func(k, m);
 6 p2 = func(k, m);
 7 printf("%d, %d\n", p1, p2);
 8 return 0;
 9 }
10 
11 int func(int a, int b) {
12 static int m = 0, i = 2;
13 i += m + 1;
14 m = i + a + b;
15 return m;}

 

 

 1 #include<stdio.h>
 2 long long func(int n);
 3 int main()
 4 {
 5     int n;
 6     long long f;
 7     while (scanf_s("%d", &n) != EOF)
 8     {
 9         f = func(n);
10         printf("n=%d,f=%lld\n", n, f);
11     }
12     return 0;
13 }
14 long long func(int n)
15 {
16     long long Y;
17     if (n == 1)
18          Y= 1;
19     else
20          Y= 2 * (func(n - 1) + 1) - 1;
21     return Y;
22 }

 

 

 1 #include<stdio.h>
 2 int func(int n, int m);
 3 
 4 int main()
 5 {
 6     int n, m;
 7     while (scanf_s("%d%d", &n, &m) != EOF)
 8         printf("n=%d,m=%d,ans=%d\n", n, m, func(n, m));
 9     return 0;
10 }
11 int func(int n, int m)
12 {
13     int Y;
14 
15     if (n == m || m == 0)
16         return 1;
17 
18     if (n < m)
19         return 0;
20 
21     else
22         Y = func(n - 1, m) + func(n - 1, m - 1);
23     return Y;
24 }

 

 

 1 #include <stdio.h> 
 2 int mul(int n, int m);
 3 int main()
 4 {
 5     int n, m;
 6     while (scanf_s("%d%d", &n, &m) != EOF)
 7         printf("%d * %d = %d\n", n, m, mul(n, m));
 8     return 0;
 9 }
10 int mul(int n, int m)
11 {
12 
13     if (m == 0)
14         return 0;
15 
16     else
17         return n + mul(n, m - 1);
18 
19 }

 

 

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

 

 

#include<stdio.h>
#include<stdlib.h>
int is_prime(int n);

int main()
{
    int i, a, b;
    for (i = 1; i <= 20; ++i)
    {
        if (i % 2 == 0) {

            for (a = 2; a < i; a++) {
                b = i - a;
                if (is_prime(b) && is_prime(a) && b != 0) {
                    printf("%d=%d+%d\n", i, a, b);

                    break;


                }
            }

        }
        else continue;
    }
}
int is_prime(int n)
{
    int i;
    int y = 1;
    for (i = 2; i < n; ++i)
    {
        if (n % i== 0)
        {
            y = 0;
            break;
        }

    }

    return y
        ;
}

 

 

 1 #include <stdio.h>
 2 #include<stdlib.h>
 3 #include<math.h>
 4 long fun(long s);
 5 
 6 int main()
 7 {
 8     long s, t;
 9     printf("Enter a number: ");
10     while (scanf_s("%ld", &s) != EOF)
11     {
12         t = fun(s);
13         printf("new number is: %ld\n\n", t);
14         printf("Enter a number: ");
15     }
16     return 0;
17 }
18 
19 long fun(long s)
20 {
21     int ans[100], i, t = 0, j, a;
22     long sum = 0;
23     for (i = 0; i <= 100; i++)
24     {
25         a = s % 10;
26         s = s / 10;
27         if (a % 2 == 1)
28         {
29             ans[t] = a;
30             t++;
31         }
32         else continue;
33     }
34     for (j = t - 1; j >= 0; j--)
35     {
36         sum = sum * 10 + ans[j];
37     }
38     return sum;
39 
40 }

 

标签:return,int,long,char,实验,func,include
From: https://www.cnblogs.com/kennthy/p/16863076.html

相关文章

  • 实验三
    task1#include<stdio.h>#include<stdlib.h>#include<time.h>#include<windows.h>#defineN80voidprint_text(intline,intcol,chartext[]);voidprint_spaces......
  • 实验3
    #include<stdio.h>#include<stdlib.h>#include<time.h>#include<windows.h>#defineN80voidprint_text(intline,intcol,chartext[]);//函数声明void......
  • 实验二
    一、实验目的能够对OpenvSwitch进行基本操作;能够通过命令行终端使用OVS命令操作OpenvSwitch交换机,管理流表;能够通过Mininet的Python代码运行OVS命令,控制网络拓扑中的Open......
  • 实验6:开源控制器实践——RYU
    一、实验目的1、能够独立部署RYU控制器;2、能够理解RYU控制器实现软件定义的集线器原理;3、能够理解RYU控制器实现软件定义的交换机原理。二、实验环境Ubuntu20.04Desktop......
  • 实验3
    #include<stdio.h>#include<stdlib.h>#include<time.h>#include<windows.h>#defineN80voidprint_text(intline,intcol,chartext[]);voidprint_spaces......
  • 实验2:Open vSwitch虚拟交换机实践
    (一)基本要求1.ovs-vsctl基础操作实践:创建OVS交换机,以ovs-xxxxxxxxx命名,其中xxxxxxxxx为本人学号。在创建的交换机上增加端口p0和p1,设置p0的端口号为100,p1的端口号为101,类型......
  • 实验3
    #include<stdio.h>#include<stdlib.h>#include<time.h>#include<windows.h>#defineN80voidprint_text(intline,intcol,chartext[]);voidprint_spaces(in......
  • 软件工程基础Y-实验一-荆雪冰
    (1)回顾你过去将近3年的学习经历当初你报考的时候,是真正喜欢计算机这个专业吗?比较喜欢,但更多是为了就业考虑。你现在后悔选择了这个专业吗?不会后悔。你认为你现在最......
  • 软件工程实验1
    (1)回顾你过去将近3年的学习经历当初你报考的时候,是真正喜欢计算机这个专业吗?当初还不太了解软件工程这个专业是干什么的,所以没有很喜欢,入学一段时间才慢慢了解。你......
  • 实验7:基于REST API的SDN北向应用实践
    一、实验目的能够编写程序调用OpenDaylightRESTAPI实现特定网络功能;能够编写程序调用RyuRESTAPI实现特定网络功能。三、实验要求(一)基本要求编写Python程序,调用Ope......