Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,395 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,117 people online right now. Registration is fast and FREE... Join Now!




L value

 
Reply to this topicStart new topic

L value, L value in C prog.

sdasin4
25 Oct, 2006 - 10:19 PM
Post #1

New D.I.C Head
*

Joined: 19 Aug, 2006
Posts: 1


My Contributions
i was asked to generate upto n-terms of fibonacci series using recursive function in C PROGRAM. I WROTE the following PROGRAM FOR IT:
CODE

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
User is offlineProfile CardPM
+Quote Post

gregoryH
RE: L Value
26 Oct, 2006 - 12:17 AM
Post #2

D.I.C Regular
Group Icon

Joined: 4 Oct, 2006
Posts: 417


Dream Kudos: 50
My Contributions
QUOTE(sdasin4 @ 25 Oct, 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:
CODE

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
User is offlineProfile CardPM
+Quote Post

Trogdor
RE: L Value
26 Oct, 2006 - 03:04 AM
Post #3

D.I.C Addict
Group Icon

Joined: 6 Oct, 2006
Posts: 533



Thanked: 3 times
Dream Kudos: 125
My Contributions
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));
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/5/08 02:43AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month