首页 > 其他分享 >实验三

实验三

时间:2023-11-05 19:55:50浏览次数:33  
标签:10 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 
 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     for(i=1;i<=10;++i)
17     {
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  for(i = 1; i <= n; ++i)
28        printf(" ");
29 }
30 void print_blank_lines(int n) {
31         int i;
32  
33  for(i = 1; i <= n; ++i)
34        printf("\n");
35  }
36  void print_text(int line, int col, char text[]) {
37       print_blank_lines(line-1); 
38       print_spaces(col-1); 
39       printf("%s", text); 
40 }

实验一截图

实验二

 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 long long fac(int n){
16     static long long p=1;
17     printf("p=%lld\n",p);
18     p=p*n;
19     return p;
20 }
 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     return 0;
11 }
12 
13 int func(int a,int b){
14     static int m=0,i=2;
15     i+=m+1;
16     m=i+a+b;
17     
18     return m;
19 }

 

 

实验二截图

 

实验三

 

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

实验三截图

实验四

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

 

实验四截图

实验五

 1 #include<stdio.h>
 2 
 3 void hanoi(unsigned int n,char from,char temp,char to,int count);
 4 void moveplate(unsigned int n,char from,char to);
 5 
 6 int main(){
 7     unsigned int n;
 8     int count=0;
 9     while(scanf("%u",&n)!=EOF){
10         hanoi(n,'A','B','C',count);
11         printf("cishu:",count);
12     }
13     return 0;
14 }
15 
16 void hanoi(unsigned int n,char from,char temp,char to,int count){
17     if(n==1){
18     moveplate(n,from,to);
19     count++;
20 }
21     else
22     {
23         hanoi(n-1,from,to,temp,count);
24         count++;
25         moveplate(n,from,to);
26         hanoi(n-1,temp,from,to,count);
27         count++;
28     }
29 }
30 
31 void moveplate(unsigned int n,char from,char to)
32 {
33     printf("%u:%c->%c\n",n,from,to);
}

实验五截图

 

 实验六

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

实验六截图

 

标签:10,int,long,char,实验,func,include
From: https://www.cnblogs.com/cwc6276/p/17798869.html

相关文章

  • 【单片机】初次实验:Keil51的使用
    哔哩哔哩/CSDN/博客园:萌狼蓝天延时器delay(intcount){ inti,j; for(i=0;i<count;i++){ for(j=0;j<1000;j++); }}瞧一瞧题目要求:P0口接八个发光二极管,先让后面四个灯亮,再让前面四个灯亮,循坏#include<REGX51.H>delay(intcount){ inti,j; for(i=0;i<count;i+......
  • 实验3
    1.Point.h#pragmaonce#include<iostream>usingstd::cout;usingstd::endl;classPoint{public:Point(intx0=0,inty0=0);~Point()=default;intget_x()const;intget_y()const;voidshow()const;voidmove(intn......
  • 实验三
    #include<stdio.h>#include<stdlib.h>#include<time.h>#include<windows.h>#defineN80voidprint_text(intline,intcol,chartext[]);voidprint_speace(intn);voidprint_blank_lines(intn);intmain(){intline,col,i;......
  • 实验三
    1..hpp#pragmaonce#include<iostream>usingstd::cout;usingstd::endl;classPoint{public:Point(intx0=0,inty0=0);~Point()=default;intget_x()const;intget_y()const;voidshow()const;voidmove(intn......
  • 实验二
    #include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineN1374#defineN2465intmain(){intnumber;inti;srand(time(0));for(i=0;i<N;++i){number=rand()%(N2-1+1)+N1;printf("......
  • 实验三
    1.test11#include<stdlib.h>2#include<time.h>3#include<windows.h>4#defineN805#include<stdio.h>67voidprint_text(intline,intcol,chartext[]);8voidprint_spaces(intn);9voidprint_blank_lines(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_lines(intn);......
  • 实验3 C语言函数应用编程
    一、实验目的二、实验准备三、实验内容1.实验任务1源代码:1#include<stdio.h>2#include<stdlib.h>3#include<time.h>4#include<windows.h>5#defineN8067voidprint_text(intline,intcol,chartext[]);//函数声明8voidprint_spaces(in......
  • 实验3
    #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......
  • 实验3 C语言函数应用编程
    实验任务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);intmain(){intline,col,......