首页 > 其他分享 >实验3

实验3

时间:2022-11-08 20:55:41浏览次数:41  
标签:return int long char 实验 func printf



 

#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_spaces(int n); // 函数声明
void print_blank_lines(int n); // 函数声明
int main() {
    int line, col, i;
    char text[N] = "hi, November~";
    srand(time(0)); // 以当前系统时间作为随机种子
    for (i = 1; i <= 10; ++i) {
        line = rand() % 25;  //产生0-24之间的随机整数,即小黑屏有25行
        col = rand() % 80;   //产生0-79之间的随机整数,即小黑屏有80列
        print_text(line, col, text);
        Sleep(1000); // 暂停1000ms
    }
#include<stdio.h>
long long fac(int n);
int main()
{
    int i, n;
    printf("Enter n:");
    scanf_s("%d", &n);

    for (i = 1; i <= n; ++i)
        printf("%d!=%11d\n", i, fac(i));
    return 0;
}
long long fac(int n)
{
    static long long p = 1;
    printf("p=%11d\n", p);
    p = p * n;
    return p;
}

#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;
}

#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 a;
    if (n >= 1)
    {
        a = 2 * func(n - 1) + 1;
    }
    else { a = 0; }
    return a;
}

#include<stdio.h>
int func(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, func(n, m));
    return 0;
}
int func(int n,int m)
{
        if (n < m)
        {
            return 0;
        }
        else if(m == 0)
        {
            return 1;
        }
        else if (n == m)
        {
            return 1;
        }
        else
        {
            return func(n - 1, m - 1) + func(n - 1, m);
        }
}

#include <stdio.h>
int mul(int n, int m);
int main() {
    int n, m;
    while (scanf_s("%d%d", &n, &m) != EOF)
        printf("%d*%d=%d\n", n, m, mul(n, m));

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

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
void moveplate(unsigned int n, char from, char to);
void hanoi(unsigned int n, char from, char temp, char to);
int count = 0;
int main()
{
    unsigned int n;
    printf("请输入你需要进行移动的盘子数:\n");
    while (scanf("%d", &n) != EOF)
    {
        count = 0;
        printf("请输入你需要进行移动的盘子数:\n");
        hanoi(n, &apos;A&apos;, &apos;B&apos;, &apos;C&apos;);
        printf("移动盘子的总次数为:%d\n", count);
    }
    return 0;
}
void moveplate(unsigned int n, char from, char to)
{
    printf("%u:%c-->%c\n", n, from, to);
    count++;
}
void hanoi(unsigned int n, char from, char temp, char to)
{
    if (n == 1)
    moveplate(n, from, to);
    else
    {
        hanoi(n - 1, from, to, temp);
        moveplate(n, from, to);
        hanoi(n - 1, temp, from, to);
    }
}

#include <stdio.h>
#define _CRT_SECURE_NO_WARNINGS
int is_prime(int n) {
    int i;
    if (n <= 1)return 0;
    for (i = 2;i < n;i++) {
        if (n % i == 0)return 0;
    }
    return 1;
}
int main() {
    int x, y;
    for (x = 1;x <= 20;x++)
    {
        if (x % 2 == 0)
        {
            for (y = 1;y <= x;y++)
            {
                if (is_prime(y) && is_prime(x - y) && y <= x - y)
                printf("%d=%d+%d\n", x, y, x - y);
            }
        }
    }
}

#include<stdio.h>
long fun(long s);
int main() {
    long s, t;

    printf("Enter a number:");
    while (scanf_s("%ld", &s) != EOF)
    {
        t = fun(s);
        printf("new number is:%ld\n\n", t);
        printf("Enter a number:");

    }
    return 0;
}
long fun(long s) {
    int a, b, i, d; int num[100];
    a = 0; i = 0; d = s;
    while (d != 0) {
        if (d % 2==1) {
            num[i] = d % 10;
            i++;
        }
        d = d / 10;
    }
    for (b = i - 1; b >= 0; b--) {
        a = a * 10 + num[b];
    }
    return a;

}

 

return 0;
}
// 打印n个空格
void print_spaces(int n) {
    int i;
    for (i = 1; i <= n; ++i)
        printf(" ");
}
// 打印n行空白行
void print_blank_lines(int n) 
{
    int i;
    for (i = 1; i <= n; ++i)
        printf("\n");
}
// 在第line行第col列打印一段文本
void print_text(int line, int col, char text[]) {
    print_blank_lines(line - 1); // 打印(line-1)行空行
    print_spaces(col - 1); // 打印(col-1)列空格
    printf("%s", text); // 在第line行、col列输出text中字符串
}

 

标签:return,int,long,char,实验,func,printf
From: https://www.cnblogs.com/1234wwh/p/16871151.html

相关文章

  • 实验4 类与数组、指针
    实验五vectorint.h#pragmaonce#include<iostream>usingnamespacestd;classvectorInt{public: ints,*p; vectorInt(intm) { p=newint[m]; s......
  • 实验3
    #include<stdio.h>#include<stdlib.h>#include<time.h>#include<windows.h>#defineN80voidprint_test(intline,intcol,chartest[]);voidprint_spaces(int......
  • 实验4 类与数组、指针
    Task1~4浅复制:inta=10;intb=a;可用于静态内存的复制。对于简单的类,默认的复制构造函数已经够用了,但当类持有其他资源,如动态分配的内存、指针等,就需要用到深复制......
  • 实验四
    实验任务五cpp#include<iostream>#include"vectorInt.hpp"voidtest(){usingnamespacestd;intn;cin>>n;vectorIntx1(n);for(aut......
  • 第一次实验题目
    1.题目:最大连续子数组和(最大子段和)问题:给定n个整数(可能为负数)组成的序列a[1],a[2],a[3],…,a[n],求该序列如a[i]+a[i+1]+…+a[j]的子段和的最大值。当所给的整数均为负数......
  • 实验四
    //task.5.cpp#include<iostream>#include"vectorInt.hpp"voidtest(){usingnamespacestd;intn;cin>>n;vectorIntx1(n);for(au......
  • 实验四类和对象数组及指针
    11#pragmaonce22#include<iostream>3344usingstd::cout;55usingstd::endl;6677classvectorInt{88public:99//构造......
  • 223201062522-软件工程基础Y- 实验一 刘晋
      沈阳航空航天大学软件工程基础实验报告实验名称:实验一实验题目:个人项目完成时间:2022年11月1实验内容及要求1.1教学内容及要求建立个人博客,完......
  • 实验三
    #include<stdio.h>#include<stdlib.h>#include<time.h>#include<windows.h>#defineN80voidprint_text(intline,intcol,chartext[]);//函数声明voidp......
  • 实验3
    #include<stdio.h>#include<stdlib.h>#include<time.h>#include<windows.h>#defineN80voidprint_text(intline,intcol,chartext[]);voidprint_spaces(int......