+ 1
What is the problem with this program --
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) { int fibonacci(int n){ if(n==1)return1; else if (n==0)return1; else{ return fibonacci(n-1)+fibonacci(n-2); } } } } }
3 Réponses
+ 2
thank you for your ans. but I can't execute the program
0
your method needs to be outside of Main. you have to return an int. doesnt exist or have a value, so n-1 is an error as is n-2. your if statements need { } around the returns. .. There are a number of problems. run the program and work they each error 1 at a time.
0
What is the problem with this program --
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SoloLearn
{
class Program
{
public int fibonacci(int n){
if(n==1){return 1;}
else if (n==0){return 1;}
else{ return 2;}
}
static void Main(string[] args)
{
int n=0; fibonacci(n-1)+fibonacci(n-2);
}
}
}