c语言的有参无返回值函数 c语言中有参函数和无参函数( 二 )


前面将的都是变量与变量之间的值传递,其实函数也可以传递数组之间的值 。看下面的例子:
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语言中有参函数和无参函数的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息 , 记得收藏关注本站 。