实验三

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;



}

 

 

posted @ 2023-11-04 10:09  李宇晨呵呵  阅读(30)  评论(0)    收藏  举报