|
Zoals je hierboven kunt zien, worden de eerste twee cijfers toegevoegd om het derde nummer te krijgen. publieke statische int SuanFa (int i) { als(i>0) { als (1 >= i || i <= 2) Return 1; als(i>2) SuanFa(i-1) + SuanFa(i-2); } anders return 0; }
SuanFa (i-1) vertegenwoordigt het getal voordat het werd berekend. SuanFa (i-2) vertegenwoordigt het eerste tweede getal waaruit het wordt berekend. of publieke int GetNumberAtPos(int pos) { if(pos==0|| pos==1) { Return 1; } int res = GetNumberAtPos(pos - 1) + GetNumberAtPos(pos - 2); Terugkeer van Res; } of Public Int Show(Int I){
Console.WriteLine(show(30)); als(i<=0){ a=0; } if(i==1&&i<=2){ a=1;
} anders{ a=show(i-1)+show(i-2); } Return a;
}
|