首页 > 其他分享 >实验三

实验三

时间:2023-11-05 18:01:02浏览次数:32  
标签:int long char 实验 func printf include

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <windows.h>
#define N 80


void print_text(int line,int col,char text[]);
void print_speace(int n);
void print_blank_lines(int n);

int main(){
    int line,col,i;
    char text[N]="hi,novermber~";
    
    srand(time(0));
    for(i=1;i<=10;++i)
    {
        line=rand()%25;
        col=rand()%80;
        print_text(line,col,text);
        Sleep(1000);
        
    }
    return 0;
}
    
    void print_speaces(int n)
    {
    int i;
    for(i=1;i<=n;++i)
        printf(" ");
    }
    void print_blank_lines(int n){
        int i;
        
        for(i=1;i<=n;++i)
        printf("\n");
        
    }
    void print_text(int line,int col,char text[]){
        print_blank_lines(line-1);
        print_speaces(col-1);
        printf("%s",text);
    }
    
View Code

#include <stdio.h>
long long fac(int n);
int main(){
    int i,n;
    
    printf("Enter n:");
    scanf("%d",&n);
    for (i=1;i<=n;++i)
    printf("%d!=%lld\n",i,fac(i));
    
    return 0;
} 
long long fac(int n){
    static long long p=1;
    
    printf("p=%lld\n",p);
    
    p=p*n;
    return p;
}
View Code

#include <stdio.h>
int func(int,int);

int main(){
    int k=4,m=1,p1,p2;
    
    p1=func(k,m);
    p2=func(k,m);
    printf("%d,%d\n",p1,p2);
    
    return 0;
} 
int func(int a,int b){
    static int m=0,i=2;
    i+=m+1;
    m=i+a+b;
    
    return m;
}
View Code

#include <stdio.h>
 2 #include <stdlib.h>
 3 long long func(int n); // 函数声明
 4 
 5 int main() {
 6     int n;
 7     long long f;
 8 
 9     while (scanf("%d", &n) != EOF) {
10         f = func(n); // 函数调用
11         printf("n = %d, f = %lld\n", n, f);
12     }
13     system("pause");
14     return 0;
15 }
16 
17 // 函数定义
18 long long func(int n){
19     long long m;
20     if(n>=2){
21         m=(func(n-1)+1)*2-1;
22     }
23     else
24         m=1;
25 
26     return m;}
View Code

1 #include <stdio.h>
 2 #include <stdlib.h>
 3 int func(int n, int m);
 4 
 5 int main() {
 6     int n, m;
 7 
 8     while(scanf("%d%d", &n, &m) != EOF)
 9         printf("n = %d, m = %d, ans = %d\n", n, m, func(n, m));
10     
11     system("pause");
12     return 0;
13 }
14 
15 // 函数定义
16 int func(int n,int m){
17     int i,s;
18     int a=1,b=1;
19     for(i=n;i>=(n-m+1);--i)
20         b=b*i;
21     for(i=1;i<=m;++i)
22         a=a*i;
23     s=b/a;
24     return s;}
View Code

 


 

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

 1 long func(long s);//函数声明
 2 
 3 int main()
 4 {
 5     long s,t;
 6 
 7     printf("Enter a number:");
 8     while (scanf("%ld",&s)!=EOF){
 9         t=func(s);
10         printf("new number is:%ld\n\n",t);
11         printf("Enter a number:");
12     }
13     system("pause");
14     return 0;
15 }
16 
17 long func(long s)
18 {
19     int a,b;
20     int i=1,c=0;
21     do
22     {
23         a=s%10;
24         s=s/10;
25         b=a%2;
26         if(b!=0)
27         {
28             c=a*i+c;
29             i*=10;
30         }
31     }while(s>=1);
32 
33     return c;
34 }
View Code

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 
 4 int main()
 5 {
 6     //从47开始,平方、立方才能用到10个数字    
 7     int t,a,b,c,d,e,m,n,p,q,z;
 8     for(t=47;t<100;++t)
 9     {
10         b=t*t*t;
11         m=b%10;
12         b=b/10;
13         n=b%10;
14         if(m!=n){
15             b=b/10;
16             p=b%10;
17             if(p!=n&&p!=m){
18                 b=b/10;
19                 q=b%10;
20                 if(q!=m&&q!=n&&q!=p){
21                     b=b/10;
22                     z=b%10;
23                     if(z!=m&&z!=n&&z!=p&&z!=q){
24                         b=b/10;
25                         if(b!=m&&b!=n&&b!=p&&b!=q&&b!=z){
26                             a=t*t;
27                             c=a%10;
28                             a=a/10;
29                             d=a%10;
30                             if(c!=d&&c!=m&&c!=n&&c!=p&&c!=q&&c!=z&&c!=b){
31                                 a=a/10;    
32                                 e=a%10;
33                                 if(e!=c&&e!=d&&e!=d&&e!=m&&e!=n&&e!=p&&e!=q&&e!=z&&e!=b){
34                                     a=a/10;
35                                     if(a!=c&&a!=d&&a!=e&&a!=m&&a!=n&&a!=p&&a!=q&&a!=z&&a!=b){
36                                         printf("找到数字%d\n",t);}}}}}}}}
37     }
38                                     
39     system("pause");
40     return 0;
41 }
View Code

 

 

标签:int,long,char,实验,func,printf,include
From: https://www.cnblogs.com/LHLH0512/p/17810833.html

相关文章

  • 实验三
    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,......
  • 实验3 C语言函数应用编程
    1、实验1实验1运行结果  实现了每隔一秒随机弹出“hi,November~”。2、实验2实验2-1源代码1#include<stdio.h>2longlongfac(intn);34intmain()5{6inti,n;78printf("Entern:");9scanf("%d",&n);1011for......
  • 实验三
    task1.c源代码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_bl......
  • 实验3 类与数组、指针
    实验任务1point.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;voidmo......