+ 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); } } } } }

18th Sep 2018, 3:35 PM
Md Ibrahim (West Bengal, India)
Md Ibrahim (West Bengal, India) - avatar
3 ответов
+ 2
thank you for your ans. but I can't execute the program
18th Sep 2018, 4:20 PM
Md Ibrahim (West Bengal, India)
Md Ibrahim (West Bengal, India) - avatar
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.
18th Sep 2018, 4:12 PM
LordHill
LordHill - avatar
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); } } }
18th Sep 2018, 4:24 PM
LordHill
LordHill - avatar