首页 > 其他分享 >实验3

实验3

时间:2023-10-30 17:46:28浏览次数:21  
标签:截图 include int long 实验 func main

实验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     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);
22     }
23     return 0;
24 }
25 void print_spaces(int n){
26     int i;
27     
28     for(i=1;i<=n;++i)
29         printf(" ");
30         
31 }
32 
33 void print_blank_lines(int n){
34     int i;
35     
36     for(i=1;i<=n;++i)
37         printf("\n");
38 }
39 
40 void print_text(int line,int col,char text[]){
41     print_blank_lines(line-1);
42     print_spaces(col-1);
43     printf("%s",text);
44 }

截图

 实验2

2.1.1代码

 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     for (i = 1; i <= n; ++i)
10         printf("%d! = %lld\n", i, fac(i));
11         
12         return 0;
13         
14 }
15 long long fac(int n){
16     static long long p = 1;
17     
18     p = p * n;
19     
20     
21     return p;
22 }

截图

 代码2.1.2

 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     for (i = 1; i <= n; ++i)
10         printf("%d! = %lld\n", i, fac(i));
11         
12         return 0;
13         
14 }
15 long long fac(int n){
16     static long long p = 1;
17     
18     p = p * n;
19     printf("p = %lld\n", p);
20     
21     return p;
22 }

截图

 代码2.2

 1 #include <stdio.h>
 2 int func(int, int);
 3 
 4 
 5 int main(){
 6     int k = 4,m = 1, p1, p2;
 7     
 8     p1 = func(k,m);
 9     p2 = func(k,m);
10     printf("%d, %d\n", p1, p2);
11     
12     return 0;
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 }

截图

实验3

代码

 

标签:截图,include,int,long,实验,func,main
From: https://www.cnblogs.com/z00z/p/17798400.html

相关文章

  • 实验三
    实验一结果,会在随机的某一行(<25)某一列出现输出实验二结果:实现阶乘,static保证每一次循环中p的值会随之而改变,相当于我们只初始化一次p这个变量、实验三#include<stdio.h>#include<stdio.h>longlongfunc(intn);//函数声明intmain(){intn;longlongf;......
  • 实验3
    task1.c实现功能:延迟打印,以实现游戏运行的效果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);......
  • 大数据实验
       ......
  • 实验3 C语言函数应用编程
    实验任务1源代码task1.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);9voidprint_blank_lines(......
  • 实验3
    实验任务1:通过三个函数,达成每隔相同的时间在随机的行和位置输出相同的文本的效果#include<stdio.h>#include<stdlib.h>#include<time.h>#include<windows.h>#defineN80voidprint_text(intline,intcol,chartext[]);//函数声明voidprint_spaces(intn);......
  • 实验3
    任务1源代码1#include<stdio.h>2#include<stdlib.h>3#include<time.h>4#include<windows.h>5#defineN806voidprint_text(intline,intcol,chartext[]);//函数声明7voidprint_spaces(intn);//函数声明8voidprint_blank......
  • 实验三
    #include<stdio.h>longlongfunc(intn);//函数声明intmain(){intn;longlongf;while(scanf("%d",&n)!=EOF){f=func(n);//函数调用printf("n=%d,f=%lld\n",n,f);}return0;......
  • 实验三
    #include<stdio.h>longlongfunc(intn);//函数声明intmain(){intn;longlongf;while(scanf("%d",&n)!=EOF){f=func(n);//函数调用printf("n=%d,f=%lld\n",n,f);}return0;......
  • 实验3
    实验11#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);101......
  • 实验3
    task1line17-19循环10次并随机赋给line0~24其中一个数,给col0~79其中一个数voidprintf_spaces打印n个空格 voidprintf_blank_lines打印n行空白voidprintf_text利用随机生成的line与col打印出line-1与col-1空白行与空格后,光标在第line行第col列打印出文本。......