0
What is wrong with my code?
5 Answers
0
it doesnt return anything
+ 1
MINHENG LI Show your attempt first.
+ 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);
}
}
}
+ 1
thank you so much
i understand now
appreciate it
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);
}