使用功能的程序的说明 [英] Explanation of a program using functions
问题描述
#include <stdio.h>
float a(int n);
main()
{
int N;
float z;
puts("Dose to n (>=2)");
scanf("%d",&N);
z=a(N);
printf("Gia n=%d h anadromikh sxesh dinei %f\n",N,z);
}
float a(int n)
{
if(n==2)
return (7);
else if(n==3)
return ((8*49-1)/1);
else
return ((8*a(n-1)*a(n-1)-1)/a(n-2));
}
家伙可以请你解释一下我这个程序是如何工作的?
我的意思是,如果我把例如N = 8,它将如何找到A7,A6等,因此获得A8 ??
guys can you please explain me how this program works? i mean, if i put for example n=8 , how will it find a7,a6 etc so it get the a8 ??
推荐答案
基本上,
在C \\ C ++编程上的的堆栈段 在内存中。的在这里看到
In C\C++ Programming the function call work on Stack Segment in Memory.See Here
和在你的程序你递归调用功能。
and in your program you are calling function recursively.
收益率((8 * A(N-1)* A(N-1)-1)/ A(N-2));
在这个阶段输入 N = 8
该功能都将是
的(8) - &GT;(8 *一(7)*一(7)-1)/ A(6)))
对于一(7) - > (8 *一(6)*一(6)-1)/ A(5)))
的(6) - > (8 *一(5)*一(5)-1)/ A(4)))
的(5) - > (8 *一(4)*一(4)-1)/ A(3)))
对于 A(4) - > (8 *一(3)*一(3)-1)/ A(2)))
的(3)方案将返回(8 * 49-1)/ 1
的(2)方案将返回(7)
所有这些功能将获得自己的堆栈段在堆栈存储器。
These all function will get its own stack segment in stack memory.
和堆栈段,因为它适用于 LIFO 。
And the stack segment as it works on LIFO.
堆栈段将会从去年的一(8) - >一(7) - >一(6) - >一(5) - >一(4) - >一(3) - >一(2)并这取决于compiler`s函数调用方法,以便堆栈段函数调用可能会有所不同。
希望这将有助于你理解。
the stack segment will be from Last a(8)->a(7)->a(6)->a(5)->a(4)->a(3)->a(2) and it depends on the compiler`s function calling methodology so stack segment function calling may vary. hope this will help you to understand.
这篇关于使用功能的程序的说明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!