i need them seprately public static int factorial ( int n ) Return n factorial,
ID: 3529090 • Letter: I
Question
i need them seprately
Explanation / Answer
public static int factorial(int n)
{
int fact=1;
for(int i=1;i<=n;i++) fact=fact*i;
return fact;
}
public static long Fibonacci(int n)
{
long f1=0,f2=1,count=1;
if(n<=0) return 0;
else if(n==1) return 1;
else{
while(count < n)
{
count++;
long t=f1+f2;
f1=f2;
f2=t; // f2 stores fibonacci(count)
}
return f2;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.