L value

L value in C prog.

Page 1 of 1

2 Replies - 11395 Views - Last Post: 26 October 2006 - 04:04 AM Rate Topic: -----

#1 sdasin4  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 19-August 06

L value

Post icon  Posted 25 October 2006 - 11:19 PM

i was asked to generate upto n-terms of fibonacci series using recursive function in C PROGRAM. I WROTE the following PROGRAM FOR IT:
main()
{
  int n,f;
 lrscr();
  printf("enter any number limit");
  scanf("%d",&n);
  f=fibo(n);
  printf("\n%d",f);
  getch();
}
 fibo(int n)
{ 
  if(n==0||n==1)
 return 1;
 else
 {
   fibo(n)=fibo(n-1)+fibo(n-2);
  return n;
 }
}
 

when i COMPILED THE ABOVE WRITTEN PROGRAM IT SHOWED:

L VALUE REQUIRED

WHAT'S THIS L VALUE THING?

CAN ANY1 CAN HELP ME OUT PLSSSSSSSS.
'COZ OF THIS L VALUE PROBLEM I CAN'T RUN THE PROGRAM.


HELP ME POT PLSSSSS.
WILL BE REALLLLLY grateful
THX. in advance

EDIT: Added Code Tags - born2c0de

Is This A Good Question/Topic? 0
  • +

Replies To: L value

#2 gregoryH  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 60
  • View blog
  • Posts: 656
  • Joined: 04-October 06

Re: L value

Posted 26 October 2006 - 01:17 AM

View Postsdasin4, on 25 Oct, 2006 - 11:19 PM, said:

i was asked to generate upto n-terms of fibonacci series using recursive function in C PROGRAM. I WROTE the following PROGRAM FOR IT:
main()
{
  int n,f;
 lrscr();
  printf("enter any number limit");
  scanf("%d",&n);
  f=fibo(n);
  printf("\n%d",f);
  getch();
}
 fibo(int n)
{ 
  if(n==0||n==1)
 return 1;
 else
 {
   fibo(n)=fibo(n-1)+fibo(n-2);
  return n;
 }
}


when i COMPILED THE ABOVE WRITTEN PROGRAM IT SHOWED:

L VALUE REQUIRED

WHAT'S THIS L VALUE THING?

CAN ANY1 CAN HELP ME OUT PLSSSSSSSS.
'COZ OF THIS L VALUE PROBLEM I CAN'T RUN THE PROGRAM.


HELP ME POT PLSSSSS.
WILL BE REALLLLLY grateful
THX. in advance


Hi

I guess the first thing is to find out what an L VALUE is... in your code fibo(n)=fibo(n-1)+fibo(n-2); there is an equal sign....

Guess what... LVAL = RVAL... that is one meaning of L VALUE... all it means is you have a binary (takes two arguments) operator with one value on the left and one on the right. Other operators that are binary like = include +, -, /, * and %. Just swap the operator for the = in LVAL = RVAL (eg LVAL % RVAL).

Now.. to the problem at hand...

fibo(n) is a function.. and you want to deal with integers... because the type "pointer to a function" is not an integer, you are getting an L Value required error...

hope this helps
Was This Post Helpful? 0
  • +
  • -

#3 Trogdor  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 15
  • View blog
  • Posts: 627
  • Joined: 06-October 06

Re: L value

Posted 26 October 2006 - 04:04 AM

put a bit simpeler, you would want to fix 2 things:
1: the function definition should have a return type (int in this case)
2: instead of asigning the outcome of the recursive function call to another function (!! quite illegal), you should directly return its value. return(fibo(n-1)+fibo(n-2));
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1