前面将的都是变量与变量之间的值传递,其实函数也可以传递数组之间的值 。看下面的例子:
void a(int []);
main()
{
int array[5],i;
for(i=0;i5;i++) scanf("%d",array[i]);
a(array);
}
void a(int array[])
{
int i;
for(i=0;i5;i++) printf("%d\t",array[i]);
printf("\n");
}
简单c语言函数调用无返回值问题?递归函数myPower的定义有逻辑错误,改成:
double myPower(int a,int b)
{
if(0==b) return 1;
return a*myPower(a,b-1);
}
如果改成这样,会更高效:
double myPower(int a,int b)
{
if(0==b) return 1;
if(1==b) return a;
return myPower(a,b%2)*myPower(a*a,b/2);
}
例子1
#include stdio.h
double myPower(int a,int b)
{
if(0==b) return 1;
return a*myPower(a,b-1);
}
int main()
{
int a=2,b;
for(b=0;b11;b++)
printf("%lf\n",myPower(a,b));
return 0;
}
例子2
#include stdio.h
double myPower(int a,int b)
{
if(0==b) return 1;
if(1==b) return a;
return myPower(a,b%2)*myPower(a*a,b/2);
}
int main()
{
int a=3,b;
for(b=0;b11;b++)
printf("%lf\n",myPower(a,b));
return 0;
}
关于c语言的有参无返回值函数和c语言中有参函数和无参函数的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息 , 记得收藏关注本站 。
- mysql有topn
- redis的热点数据缓存 redis热点数据切换
- 如何修改戴尔服务器的IP地址? 戴尔服务器ip地址怎么改
- 无法启动mongodb 1053 安装mongodb显示没有启动权
- mysql中ext
- mysql创建数据表时指定字符集 mysql有符号创建
- 优惠券功能的业务流程设计图谱 优惠券redis处理
- redis通配符的使用
- redis是开发工具吗 redis的开发人是谁
- mongodb显示所有数据库 mongodb数据突然为空
