#include <stdio.h>
int main()
{
int x=0,y=0,i;
for (i=1;i<5;i++)
{
if ((++x>=4)||(++y)>2)
{
x++;
}
printf("x=%d \n",x);
printf("y=%d \n",y);
printf("------------- \n");
}
return 0;
}
ANS:
x=1
y=1
-------------
x=2
y=2
-------------
x=4
y=3
-------------
x=6
y=3
-------------
i=1
x=1 (F) || y=1 (F)
i=2
x=2 (F) || y=2 (F)
i=3
x=3 (F) || y=3 (T)
-->x=4
i=4
x=5 (T)
成立,所以 || 後即不用執行
-->x=6
y=3
++++++++++++++++++++++++++++++++++
#include <stdio.h>
int main()
{
int a=6,b=7;
printf("a=%d",a*=a--*--b);
return 0;
}
ANS:
a=180
a=a*(a--*--b)
=5*(6*6)
=180
++++++++++++++++++++++++++++++++++
#include <stdio.h>
int F(int n)
{
if(n==0) return 0;
if(n==1) return 1;
return F(n-1)+F(n-2);
}
int main()
{
printf("F(13)=%d",F(13));
return 0;
}
ANS:
F(13)=233
Fibonacci 數列
f(0)=0
f(1)=1
f(2)=1
f(3)=2
f(4)=3
f(5)=5
f(6)=8
f(7)=13
f(8)=21
f(9)=34
f(10)=55
f(11)=89
f(12)=144
f(13)=233
++++++++++++++++++++++++++++++++++
#include <iostream>
using namespace std;
int count=0;
int Get(int N,int M)
{
count++;
if (N==1) return (N != M ? 2:3);
else if (M==1) return 1;
else return Get(N-1,M)+Get(N-1,M-1);
}
int main()
{
int ans=Get(5,4);
cout<<"ans= "<<ans;
cout<<endl;
cout<<"count= "<<count;
}
ans= 32
count= 29