首页 > 其他分享 >实验三

实验三

时间:2023-10-30 17:46:00浏览次数:18  
标签:count int hanmo long char 实验 printf

实验一

结果,会在随机的某一行(<25)某一列出现输出

实验二

结果:实现阶乘,static保证每一次循环中p的值会随之而改变,相当于我们只初始化一次p这个变量、

实验三

#include<stdio.h>

#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) {
    long long p = 1;
    for (int i = 0; i < n; i++) {17:07:17
        p *= 2;
    }
    return p - 1;
}

实验四

#include <stdio.h>
#include<stdlib.h>
void moveplate(int n, char from, char to) {
    printf("%d:%c-->%c\n", n, from, to);
}
int  hanmo(int n, char from, char temp, char to) {
    int static count = 0;
    if (n == 1) {
        moveplate(n, from, to);
        return count+1;
    }
    else {
        hanmo(n - 1, from,to, temp);
        count++;
        moveplate(n, from, to);
        hanmo(n - 1, temp, from, to);
    }
}

int main() {
    int n = 0;
    while (scanf_s("%d", &n) != EOF) {
        int count=hanmo(n, 'A', 'B', 'C');
        printf("%d", count);
        system("pause");
    }

}

 

实验六

#include <stdio.h>
#include <math.h>
long func(long s); // 函数声明
int main() {
    long s, t;
    printf("Enter a number: ");
    while (scanf_s("%ld", &s) != EOF) {
        t = func(s); // 函数调用
        printf("new number is: %ld\n\n", t);
        printf("Enter a number: ");
    }
    return 0;
}
long func(long s) {
    int A[15] = {};
    int count = 0;
    long sum = 0;
    for (int i = 1;s!=0&&i < 50; i++) {
        if((s%10)%2!=0){
            A[count]=s%10;
            count++;
        }
        s /= 10;
    }
    for (int j = count; j>=0; j--) {
        sum += A[j];
        printf("%d", sum);
        sum *= 10;
    }

    return sum/10;
}

实验五

#include <stdio.h>
#include<stdlib.h>
void moveplate(int n, char from, char to) {
    printf("%d:%c-->%c\n", n, from, to);
}
int  hanmo(int n, char from, char temp, char to) {
    int static count = 0;
    if (n == 1) {
        moveplate(n, from, to);
        return count+1;
    }
    else {
        hanmo(n - 1, from,to, temp);
        count++;
        moveplate(n, from, to);
        hanmo(n - 1, temp, from, to);
    }
}

int main() {
    int n = 0;
    while (scanf_s("%d", &n) != EOF) {
        int count=hanmo(n, 'A', 'B', 'C');
        printf("%d", count);
        system("pause");
    }

}

 

标签:count,int,hanmo,long,char,实验,printf
From: https://www.cnblogs.com/xuyi5448/p/17798417.html

相关文章

  • 实验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列打印出文本。......
  • 实验3
    task11#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_l......