首页 > 其他分享 >实验三

实验三

时间:2024-04-24 20:35:51浏览次数:18  
标签:return int long char 实验 func 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_spaces(int n);  
void print_blank_lines(int n); 

int main() {
	int line, col, i;
	char text[N] = "hi, April~";
	
	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_spaces(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_spaces(col - 1);
	printf("%s", text);  
}

 

作用是在随机行列生成Hi,April~

实验任务二

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

    p = p * n;

    return p;
}

#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=%1ld\n", p);

    p = p * n;

    return p;
}

#include <stdio.h>
#include<stdlib.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);
	system("pause");
    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>
#include<stdlib.h>
long long func(int n); // 函数声明

int main() {
    int n;
    long long f;

    while (scanf("%d", &n) != EOF) {
        f = func(n); // 函数调用
        printf("n = %d, f = %lld\n", n, f);
    }
	system("pause");
    return 0;
}
long long func(int n)
{
	if(n==0){
		return 0;}
	if(n>=1){
		return 2*func(n-1)+1;}

}

实验任务四

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

int main() {
	int n, m;

	while (scanf("%d%d", &n, &m) != EOF)
		printf("n = %d, m = %d, ans = %d\n", n, m, func(n, m));
	system("pause");
	return 0;
}
int func(int n, int m)
{

	int s = 1, k = 1;
	int i, j;
	if (n < m){
		return 0;}
	if (n == m || m == 0){
		return 1;}
	if (n > m)
	{
		for (i = n; i >= n - m + 1; i--)
			s *= i;
		for (j = 1; j <= m; j++)
			k *= j;
		return s / k;
	}


}

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

int main() {
	int n, m;

	while (scanf("%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 (m == 0 || m == n) {
		return 1;
	}
	if (m > n) {
		return 0;
	}
	if (n > m) {
		return func(n - 1, m) + func(n - 1, m - 1);
	}
}

 

实验任务五

#include <stdio.h>
#include<stdlib.h>
void hanio(int n,char from,char temp,char to); 
void moveplate(int n,char from,char to);
int sum(int n);
int main() 
{
	int k;
	char A,B,C;
	int n;
	while(scanf("%d",&n)!=EOF)
	{
   hanio(n,'A','B','C');
   k=sum(n);
   printf("一共移动了%d次\n",k);
	system("pause");
	}
    return 0;
}
void moveplate(int n,char from,char to)
{
	
	printf("%d : %c --> %c\n",n,from,to);

}
void hanio(int n,char from,char temp,char to)
{
	if(n==1){
		moveplate(n,from,to);}
	if(n>1)
	{
	hanio(n-1,from,to,temp);
	moveplate(n,from,to);
	hanio(n-1,temp,from,to);
	}
}
int sum(int n)
{
	if(n==1){
		return 1;}
	if(n>1){
		return 2*sum(n-1)+1;}

}

实验任务六

#include <stdio.h>
#include <math.h>
long func(long s); 

int main( ) {

    long s, t;

    printf("Enter a number: ");
    while (scanf("%ld", &s) != EOF) {
        t = func(s); // 函数调用
        printf("new number is: %ld\n\n", t);
        printf("Enter a number: ");
    }

    return 0;
}
long func(long s) {
    long a;
    long x, t;

    a = 0;
    t = 1;

    while (s != 0) {
        x = s % 10;

        if (x % 2) {
            a += t * x;
            t *= 10;
        }

        s /= 10;
    }
        return a;
}

标签:return,int,long,char,实验,func,include
From: https://www.cnblogs.com/pjypjy/p/18156271

相关文章

  • 互斥锁(实验)(不严谨)
    进程与进程的锁和线程与线程的锁是不一样的。abc三部曲pthread_mutex_tlock=PTHREAD_MUTEX_INITIALIZER;//创建一个锁pthread_mutex_lock(&lock);//上锁pthread_mutex_unlock(&lock);//开锁对于全局变量,共享数据就是临界区,需要使用锁。intticketAmount=2;//这里......
  • XMU《UNIX 系统程序设计》第二次实验报告
    一、实验内容描述实验目的掌握与文件和目录树有关的系统调用和库函数。实验要求编写程序myfind命令语法myfind<pathname>[-comp<filename>|-name<str>...]命令语义(1)myfind<pathname>的功能除了具有与程序4-7相同的功能外,还要输出在<pathname>目录子树之下,文......
  • XMU《计算机网络与通信》第三次实验报告
    一、个人信息学号:**************姓名:###二、实验目的理解TCP和UDP协议主要特点掌握socket的基本概念和工作原理,编程实现socket通信三、实验任务与结果任务1前置任务开启两个终端窗口,分别编译、运行server_example.c和client_example.c,观察它们实现的功能。......
  • 20231325 贾罗祁 实验三《Python程序设计》实验报告
    20231325贾罗祁2023-2024-2《Python程序设计》实验三报告课程:《Python程序设计》班级:2313姓名:贾罗祁学号:20231325实验教师:王志强实验日期:2024年4月17日必修/选修:公选课1.实验内容创建服务端和客户端,服务端在特定端口监听多个客户请求。客户端和服务端通过Socket套......
  • 实验二——需求分析
    一、实验题目:需求分析二、实验目的 1、掌握StarUML软件的安装; 2、掌握利用StarUML工具分析、设计、绘制用例图;3、掌握利用StarUML工具分析、设计、绘制类图;4、掌握利用StarUML工具分析、设计、绘制状态图;5、掌握利用StarUML工具分析、设计、绘制顺序图。6、掌握利用Star......
  • 实验3
    task1.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()......
  • 数字孪生系统:实验室基地园区的高效运营新引擎
    在科技飞速发展的今天,数字化转型已成为各行各业不可逆转的趋势。实验室基地园区作为科技创新的摇篮,其数字化升级更是刻不容缓。数字孪生系统作为数字化转型的得力助手,正以其独特的魅力,引领实验室基地园区走向智慧化、高效化的新纪元。 数字孪生系统就是通过数字技术将现实世界......
  • 实验3 C语言函数应用编程
    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);//函数声明9voidpri......
  • 实验一-原型设计-虎扑评分APP
    一·对比分析墨刀,Axure,Mockplus等原型设计工具的各自的适用领域及优缺点。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);//函数声......