操作系统
1月9日 周二
实现的功能: 递归 n的k次幂 查找表
/* Note:Your choice is C IDE */
include “stdio.h”
//斐波那契数列递归
int fun(int n)//
{
if(n==1||n==2)
{
return 1;
}
else
{
return fun(n-1)+fun(n-2);
}
}
void main()
{
int n;
printf(“斐波那契数列的前20项是:\n”);
for(n=1;n<=20;n++)
{
printf(” %d “,fun(n));
}
}
/* Note:Your choice is C IDE */
include “stdio.h”
//n的k次幂
fun(int x,int k)
{
if(k==0)
{
return 1;
}
else
{
return x*fun(x,k-1);
}
}
void main()
{
int x,k;
printf(“x:”);
scanf(“%d”,&x);
printf(“k:”);
scanf(“%d”,&k);
printf("%d",fun(x,k));
}
/* Note:Your choice is C IDE */
include “stdio.h”
//查找表
comeon();
then();
void main()
{
comeon();
}
comeon()
{
int x;
int a[5]={3,1,7,5,0};
printf("请输入要查找的数:");
scanf("%d",&x);
then(x,&a);
}
then(int x,int *a)
{
int i;
for(i=0;i<5;i++)
{
if(x==a[i])
{
printf(“查找成功\n”);
}
}
}
Do not pray for an easy life, pray for the strength to endure a difficult one.– Bruce Lee
不要祈求安逸的人生,祈求拥有撑过艰难的力量。– 李小龙