首页 > 其他分享 >实验三

实验三

时间:2023-11-04 10:23:30浏览次数:23  
标签:return int long char 实验 printf include

test1

#include<stdio.h>
#include<time.h>
#include<stdlib.h>
#include<windows.h>
#define N 80
void test_(int line, int col, char test[]);
void space(int n);
void blank(int n);
int main() {
    int line, col, i;
    char test[N] = "hi ";
    srand(time(0));
    for (i = 1;i <= 10;++i) {
        line = rand() % 25;
        col = rand() % 80;
        test_(line, col,test);
        Sleep(1000);
    }
    return 0;
}
void space(int n) {
    int i;
    for (i = 1;i <= n;i++) {
        printf(" ");
    }
}
void blank(int n) {
    int i;
    for (i = 1;i <= n;i++)
        printf("\n");
}
void test_(int line, int col, int test[]) {
    blank(line - 1);
    space(col - 1);
    printf("%s", test);
}

 

 

 

test 2

 

#include<stdio.h>
long long qwe(int n);
int main() {
    int n, i;
    scanf_s("%d", &n);
    for (i = 1;i <= n;++i) {
        printf("%lld\n", qwe(i));
    }



    return 0;
}
long long qwe(int n) {
    static long long p=1;
    p = p * n;
    printf("%lld\t", p);
    return p;
}

 

 

test3

 

#include <stdio.h>
long long func(int n);
int main() {
    int n;
    long long f;
    while (scanf_s("%d", &n) != EOF) {
        f = func(n); 
        printf("n = %d, f = %lld\n", n, f);
    }
    return 0;
}
long long func(int n) {
    if (n == 1) {
        return 1;
    }
    else {
        return (func(n - 1) + 1) * 2 - 1;
    }

}

 

 

test4

#include <stdio.h>
int funcq(int n, int m);
int main() {
    int n, m;
    while (scanf_s("%d%d", &n, &m) != EOF)
        printf("n = %d, m = %d, ans = %d\n", n, m, funcq(n, m));
    return 0;
}
int funcq(int n, int m) {

    if (m == 0) {
        return 1;
    }
    if (m > n) {
        return 0;
    }
    else {
        return (funcq(n - 1, m) + funcq(n - 1, m - 1));
    }
}

 

test 5

 

#include<stdio.h>
void hanoi(unsigned int n, char from, char temp, char to);
int main()
{
    unsigned int n;
    scanf_s("%u", &n);
    hanoi(n, 'A', 'B', 'C');
    return 0;
}
void hanoi(unsigned int n, char from, char temp, char to) {
    if (n == 1) {
        printf("%u:%c-->%c\n", n, from, to);
    }
    else {
        hanoi(n - 1, from, to, temp);
        printf("%u:%c-->%c\n", n, from, to);
        hanoi(n - 1, temp, to, from);
    }

}

 

 

test 6

#include <stdio.h>
#include <math.h>
long funcw(long s);
int main6() {
    long s, t;
    printf("Enter a number: ");
    while (scanf_s("%ld", &s) != EOF) {
        t = funcw(s);
        printf("new number is: %ld\n\n", t);
        printf("Enter a number: ");
    }
    return 0;
}
long funcw(long s) {
    int weishu,i;
    i = s;
    for (weishu = 1;i != 0;weishu*=10) {
        i /= 10;
    }
    int q, w=0;
    for (;s != 0;) {
        q = s;
        q /= weishu;
        if (q % 2 != 0) {
        w = 10 * w + q;
        }
        s = s - q * weishu;
        weishu /= 10;
    }
    return w;



}

 

 

标签:return,int,long,char,实验,printf,include
From: https://www.cnblogs.com/lycxt/p/17808958.html

相关文章

  • 实验三
     ......
  • 软件设计实验7:单例模式
    实验7:单例模式本次实验属于模仿型实验,通过本次实验学生将掌握以下内容:1、理解单例模式的动机,掌握该模式的结构;2、能够利用单列模式解决实际问题。 [实验任务一]:学号的单一仿照课堂的身份证的例子,实现每个同学仅有一个学号这一问题。实验要求:1. 画出对应的类图;  2......
  • 软件设计实验6:原型模式
     实验6:原型模式本次实验属于模仿型实验,通过本次实验学生将掌握以下内容:1、理解原型模式的动机,掌握该模式的结构;2、能够利用原型模式解决实际问题。 [实验任务一]:向量的原型用C++完成数学中向量的封装,其中,用指针和动态申请支持向量长度的改变,使用浅克隆和深克隆复制向量......
  • 实验三
    #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()......
  • 实验三
    任务一task1.cpp1#include<iostream>2#include"point.hpp"3#include<vector>4usingstd::vector;5usingstd::cin;6voidoutput(constvector<Point>&v){7for(auto&t:v)8t.show();9}10voidtest()......
  • 实验3—C语言函数应用编程
    1、实验任务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_b......
  • ensp实验,大一必学网工基础,数通HCIA内容,详细知识点集合
    1:交换机通信:两个pc端在一个网段内,不用单独配置交换机信息,不用设置网关地址,都能ping通2:路由器通信:Pc的网关地址是路由器的ip地址。路由器配置接口和地址Pc3pingpc4即可3:静态路由:静态路由配置好PC的ip地址、子网掩码、网关和路由器接口的地址信息。在R7路由器输入:[R7]iproute-stat......
  • 国产教学实验箱_嵌入式实验箱:3-4 mp3音频解码实验
    一、实验目的了解MP3文件的结构,掌握MP3音频解码的原理,并实现基于SYSBIOS系统,将MP3格式的音频解码为PCM格式。二、实验原理1、MP3音频格式MP3是一种音频压缩技术,其全称是动态影像专家压缩标准音频层面3(MovingPictureExpertsGroupAudioLayerIII),简称为MP3。它被设计用来大幅度地......
  • 实验三
     #include<stdio.h>intfunc(intn,intm);intmain(){intn,m;while(scanf("%d%d",&n,&m)!=EOF)printf("n=%d,m=%d,ans=%d\n",n,m,func(n,m));return0;}intfunc(intn,intm){if(n<m)......
  • JVM 调优实验
    JVM调优理论前言关于性能优化Therealproblemisthatprogrammershavespentfartoomuchtimeworryingaboutefficiencyinthewrongplacesandatthewrongtimes;prematureoptimizationistherootofallevil(oratleastmostofit)inprogramming.—D......