寒假作业2024.2.11

文章介绍了如何使用递归方法在C语言中实现阶乘、求和、斐波那契数列、二进制转换、计算数字之和和数字乘积,以及单词逆置等基本算法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

请使用递归实现n!

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <unistd.h>
int  fun(int n) 
{
    if (n==0) 
	{
        return 1;
    } else 
	{
        return n*fun(n-1);
    }
}
int main(int argc, const char *argv[])
{
	int n;
	printf("please enter n:");
	scanf("%d",&n);
    int sum=fun(n);
    printf("%d的阶乘是: %d\n",n,sum);
	return 0;
}


请使用递归实现O-n的和

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <unistd.h>
int fun(int n)
{
    if(n==0)
        return 0;
    else
        return n+fun(n-1);
}
int main(int argc, const char *argv[])
{
	int n;
	printf("please enter n:");
	scanf("%d",&n);
    int sum=fun(n);
    printf("0-%d的和是: %d\n",n,sum);
	return 0;
}


请使用递归实现斐波那契

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <unistd.h>
int fun(int n)
{
	if(n==1||n==2)
	{
		return 1;
	}
	else
	{
		return fun(n-1)+fun(n-2);
	}
}

int main(int argc, const char *argv[])
{
	int n;
	printf("please enter n:");//n为打印的数列层数
	scanf("%d",&n);
	printf("斐波那契数列:");
	for(int i=1;i<=n;i++)
	{
		printf("%d ",fun(i));
	}
	puts("");
	return 0;
}


请使用递归实现二进制转换

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <unistd.h>
void Exchange(int n)
{
	if(n==0)
	{
		return ;	
	}
	else
	{
		Exchange(n/2);
		printf("%d",n%2);
	}	
} 

int main(int argc, const char *argv[])
{
	int n;
	printf("please enter n:");
	scanf("%d",&n);
	printf("十进制数%d转换为二进制数为:",n);
	Exchange(n);
	puts("");
	return 0;
}


请递归实现计算各个位数字之和

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <unistd.h>
int fun(int n)
{
	if(n==0)
		return 0;
	else
		return n%10+fun(n/10);
}
int main(int argc, const char *argv[])
{
	int n;
	printf("please enter n:");
	scanf("%d",&n);
	int sum=fun(n);
	printf("sum=%d\n",sum);
	return 0;
}


请递归实现计算各个位数字的乘积

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <unistd.h>
int fun(int n)
{
	if(n<10)
		return n;
	else
	{
		return n%10*fun(n/10);
	}
}
int main(int argc, const char *argv[])
{
	int n;
	printf("please enter n:");
	scanf("%d",&n);
	int sum=fun(n);
	printf("sum=%d\n",sum);
	return 0;
}


请使用递归实现计算单词逆置

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <unistd.h>
//整体逆置+单词逆置
void reverseAll(char str[], int start, int end) 
{  
	if(end-start<1)
	{
		return ;  
	}
	else
	{	
		char t=str[start];
		str[start]=str[end];
		str[end]=t;
		reverseAll(str,start+1,end-1); 
	}
}  

//逆置单词  
void reverseWords(char str[],int len) 
{  
	int start=0;  
	int end=0;  
	// 先逆置整个字符串  
	reverseAll(str,0,len-1);  
	// 再逆置每个单词  
	while (end<len) 
	{  
		// 找到原本单词的起始位置  
		while (end<len && str[end]==' ') 
		{  
			end++; // 跳过空格  
			start=end; // 更新单词的起始位置  
		}  
		// 找到原本单词的结束位置  
		while (end<len && str[end]!=' ') 
		{  
			end++; //移动到原本单词的末尾 
		}  
		// 逆置当前单词(不包括末尾的空格)  
		reverseAll(str,start,end-1);  
	}  
}  
int main(int argc, const char *argv[])
{
	char str[100]; 
	printf("Please enter str: ");  
	gets(str);	
	int len=strlen(str);         
	reverseWords(str,len);
	printf("%s\n", str);
	return 0;
}

### 回答1: 同步带张力计算软件Excel是一款基于Microsoft Excel平台开发的专业工具,用于计算同步带的张力。它提供了一组强大的功能,可以帮助用户快速且准确地计算同步带的张力,从而确保同步带在工作过程中的正常运行和可靠性。 这款软件具有以下特点和功能: 1. 界面简洁直观:软件的界面设计简单易用,用户可以轻松上手并操作。 2. 数据输入方便灵活:用户只需输入同步带的相关参数,如长度、宽度、材料等,软件会自动进行计算。 3. 自动计算功能:软件可根据输入的参数自动计算同步带的张力,不仅快速而且准确。 4. 参数调整与优化:软件还提供了一些调整参数和优化参数的功能,帮助用户根据实际情况调整同步带的张力,以获得最佳的工作效果。 5. 数据分析与报告生成:软件能够对计算结果进行分析,并根据用户需求生成相应的报告,方便用户进行后续数据分析和处理。 同步带张力计算软件Excel的使用不仅提高了计算的效率和准确性,还能够帮助用户更好地掌握同步带的工作情况,及时进行调整和维护。它适用于各种同步带应用场景,如工业生产线、传送带、运输设备等,为用户提供了便利和保障。 ### 回答2: 同步带张力计算软件Excel是一种通过使用Excel软件来计算和测量同步带张力的工具。这个软件可以帮助用户准确地计算同步带在不同工作条件下的张力,并且可以根据用户的需求进行定制化。 该软件的主要功能包括以下几个方面: 1. 同步带参数输入:用户可以通过该软件输入同步带的相关参数,如带宽、带长、带轮直径、带片数量等,以便进行后续的计算。 2. 工作条件设置:用户可以根据实际工况设置同步带的工作条件,包括初始张力、加载形式、转速等,这些参数将用于计算同步带的张力。 3. 张力计算:软件会根据用户输入的参数和设置的工作条件,通过预设的算法计算同步带的实时张力。计算结果可以以图表或数据表的形式展示,并且可以根据需要进行保存和导出。 4. 张力监测:软件还可以实时监测同步带的张力变化,并通过警报功能提醒用户是否存在异常情况。这样可以帮助用户及时了解同步带的工作状态,及时进行维护和调整。 总之,同步带张力计算软件Excel是一款功能强大的工具,可以准确地帮助用户计算和监测同步带的张力,提高工作效率和工作安全性。它的使用不仅简便快捷,而且具有较高的精度和可靠性,适用于各种同步带应用场合。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值