0

What is wrong with my code?

27th Sep 2020, 12:20 PM
MINHENG LI
MINHENG LI - avatar
5 Answers
0
it doesnt return anything
27th Sep 2020, 12:24 PM
MINHENG LI
MINHENG LI - avatar
+ 1
MINHENG LI Show your attempt first.
27th Sep 2020, 12:24 PM
Sâùtôsh
Sâùtôsh - avatar
+ 1
It loops. Try it like this, i put some comment in it: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { // index start at 1 for(int index=1;index<10;index++) { Console.WriteLine(Sequence(index)); } } public static int Sequence(int number) { // not && but || if(number==1||number==2) { return 1; } // else return else return Sequence(number-1)+Sequence(number-2); } } }
27th Sep 2020, 12:35 PM
Paul
Paul - avatar
+ 1
thank you so much i understand now appreciate it
27th Sep 2020, 12:37 PM
MINHENG LI
MINHENG LI - avatar
0
static void main(string[] args) { for(int index=0;index<10;index++) { Console.WriteLine(Sequence(index)); } } public static int Sequence(int number) { if(number==1&&number==2) { return 1; } return Sequence(number-1)+Sequence(number-2); }
27th Sep 2020, 12:24 PM
MINHENG LI
MINHENG LI - avatar