首页 > 其他分享 >实验三

实验三

时间:2023-10-31 21:11:53浏览次数:27  
标签:10 int long 实验 func printf include

test1.c

 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 
17 for(i = 1; i <= 10; ++i) {
18 line = rand() % 25;
19 col = rand() % 80;
20 print_text(line, col, text);
21 Sleep(1000); // 暂停1000ms
22 }
23 return 0;
24 
25 } // 打印n个空格
26 
27 void print_spaces(int n) {
28 int i;
29 
30 for(i = 1; i <= n; ++i)
31 printf(" ");
32 }
33 
34  // 打印n行空白行
35 void print_blank_lines(int n) {
36 int i;
37 for(i = 1; i <= n; ++i)
38 printf("\n");
39 }
40 
41 // 在第line行第col列打印一段文本
42 void print_text(int line, int col, char text[]) {
43 print_blank_lines(line-1); // 打印(line-1)行空行
44 print_spaces(col-1); // 打印(col-1)列空格
45 printf("%s", text); // 在第line行、col列输出text中字符串
46 }
View Code

功能为每隔一秒在下面第随机行随机列打出字符串

test2-1.c

 1 #include <stdio.h>
 2 long long fac(int n); // 函数声明
 3 
 4 int main() {
 5     int i, n;
 6 
 7     printf("Enter n: ");
 8     scanf("%d", &n);
 9 
10     for (i = 1; i <= n; ++i)
11         printf("%d! = %lld\n", i, fac(i));
12 
13     return 0;
14 }
15 
16 // 函数定义
17 long long fac(int n) {
18     static long long p = 1;
19 
20     p = p * n;
21 printf("p = %lld\n", p);
22     return p;
23 }
View Code

test2-2.c

 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 // 函数定义
15 int func(int a, int b) {
16     static int m = 0, i = 2;
17 
18     i += m + 1;
19     m = i + a + b;
20 
21     return m;
22 }
View Code

test3.c

 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         f = func(n); // 函数调用
10         printf("n = %d, f = %lld\n", n, f);
11     }
12 
13     return 0;
14 }
15 long long func(int n){
16     long long f;
17     if(n==1)
18     f=1;
19     else
20     f=(func(n-1)+1)*2-1;
21     
22     
23     return f;
24 } 
View Code

test4.c

 1 #include <stdio.h>
 2 int func(int n, int m);
 3 
 4 int main() {
 5     int n, m;
 6 long long ans;
 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 int func(int n, int m){
13     int i,a=1,b=1,c=1;
14     long long ans;
15     if(n<m)
16     ans=0;
17     else{
18     
19     for(i=1;i<=n;i++)
20     a*=i;
21     for(i=1;i<=m;i++)
22     b*=i;    
23     for(i=1;i<=n-m;i++)
24     c*=i;
25     ans=a/b/c;}
26     
27     
28     return ans;
29 }
View Code

 1 #include <stdio.h>
 2 int func(int n, int m);
 3 
 4 int main() {
 5     int n, m;
 6 long long ans;
 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 int func(int n, int m){
13     long long ans;
14     if(n<m)
15     ans=0;
16     else if(m==0||m==n)
17     ans=1;
18         else
19     {
20         ans=func(n-1,m)+func(n-1,m-1);
21         
22         
23             }
24     return ans;
25 }
View Code

 test5.c

 

 1 #include <stdio.h>
 2 
 3 void move(int n, char A, char B, char C);
 4 
 5 int main()
 6 {
 7     int n;
 8     char A, B, C;
 9     while (scanf("%d", &n) != EOF) {
10         int step = 0;
11         move(n, 'A', 'B', 'C');
12         for (n; n > 0; n--) {
13             step = 2 * step + 1;
14         }
15         printf("\n");
16         printf("一共移动了%d次\n", step);
17         printf("\n");
18     }
19 
20     return 0;
21 }
22 
23 void move(int n, char A, char B, char C) {
24     if (n == 1) {
25         printf("%d:%c --> %c\n", n, A, C);
26     }
27     else {
28         move(n - 1, 'A', 'C', 'B');
29         printf("%d:%c --> %c\n", n, A, C);
30         move(n - 1, 'B', 'A', 'C');
31     }
32 }
View Code

 

 

 

test6.c

 1 #include <stdio.h>
 2 #include <math.h>
 3 long func(long s); // 函数声明
 4 int main() {
 5 long s, t;
 6 printf("Enter a number: ");
 7 while (scanf("%ld", &s) != EOF) {
 8 t = func(s); // 函数调用
 9 printf("new number is: %ld\n\n", t);
10 printf("Enter a number: ");
11 }
12 return 0;
13 }
14 long func(long s)
15 {
16     int a=0,i=1;
17     float m=0.1;
18     long s1=0;
19     while(s>=1)
20     {
21         a=s%10;
22         if(a%2==1)
23         {
24         s1+=a*10*m;
25         m*=10;}
26         s/=10;
27     }
28     return s1;}
View Code

 

标签:10,int,long,实验,func,printf,include
From: https://www.cnblogs.com/zyqJ/p/17798405.html

相关文章

  • 实验3
    实验任务1实验任务2.1实验任务2.2 实验任务3实验任务4实验任务5 实验任务6 ......
  • 实验3 c语言函数应用编程
    task11源代码1#include<stdio.h>2#include<stdlib.h>3#include<time.h>4#include<windows.h>5#defineN8067voidprint_text(intline,intcol,chartext[]);8voidprint_spaces(intn);9voidprint_blank_lines(intn)......
  • 实验3
    实验任务1#include<stdio.h>#include<stdlib.h>#include<time.h>#include<windows.h>#defineN80voidprint_text(intline,intcol,chartext[]);//函数声明voidprint_spaces(intn);//函数声明voidprint_blank_lines(intn);//函数声明int......
  • 实验三
    #include<stdio.h>#include<stdlib.h>#include<time.h>#include<windows.h>#defineN80voidprint_text(intline,intcol,chartext[]);//函数声明voidprint_spaces(intn);//函数声明voidprint_blank_lines(intn);//函数声明intmain()......
  • 使用EMR+DLF+OSS-HDFS进行数据湖分析(阿里云实验)
    实验地址:https://developer.aliyun.com/adc/scenario/exp/f7cf565798e34710acf483ba56e6ebf6hadoopfs操作oss#上传文件hadoopfs-putlogtail.shoss://u-5stubb6d.cn-shanghai.oss-dls.aliyuncs.com/#新建目录hadoopfs-mkdiross://u-5stubb6d.cn-shanghai.oss-dls.aliyu......
  • 实验三
    tesk1代码#include<time.h>#include<windows.h>#defineN80voidprint_text(intline,intcol,chartext[]);voidprint_spaces(intn);voidprint_blank_lines(intn);intmain(){intline,col,i;chartext[N]="hi,November~";......
  • 实验3
    任务1源码 任务1结果生成随机弹幕: 任务2源码  任务2结果 任务3源码  任务3结果  任务4源码迭代 递归 任务4结果 迭代递归 任务5源码  任务5结果  任务6源码  任务6结果  任务7源码 1#define_CRT_SECURE_NO......
  • 实验三
    1.实验任务1每间隔1秒生成随机位置的hiNovermber实验任务2实验任务3实验任务4实验任务5 实验任务6 ......
  • 实验3 C语言函数应用编程
    一,实验目的二,实验准备三,实验内容1,实验任务1task1.c1#include<stdio.h>2#include<stdlib.h>3#include<time.h>4#include<Windows.h>5#defineN8067voidprint_text(intline,intcol,chartext[]);//函数声明8voidprint_spaces(intn);//......
  • 实验三
      实验3.1实验3.1源码#include<stdio.h>#include<stdlib.h>#include<time.h>#include<windows.h>#defineN80voidprint_text(intline,intcol,chartext[]);//函数声明voidprint_spaces(intn);//函数声明voidprint_blank_lines(in......