473,385 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Help with func

I’m taking an online course in Java programming and one of the problems on my open book test is to find the values of func1

Expand|Select|Wrap|Line Numbers
  1. Private int func1(int m, int n) {
  2. If (m==n || n==1)
  3. Return 1;
  4. Else
  5. Return func1(m-1,n-1) + n*func1(m-1,n);
  6. }
The thing is I can’t find this anywhere in my text book, and I haven’t had any algebra in 10 years. (if it is indeed algebra and I'm going off on a tangent) If you walk me thru it, don't use the values of 5, 3 because I don't want the answer.
Thank you
Oct 31 '06 #1
4 1936
r035198x
13,262 8TB
I’m taking an online course in Java programming and one of the problems on my open book test is to find the values of func1

Expand|Select|Wrap|Line Numbers
  1. Private int func1(int m, int n) {
  2. If (m==n || n==1)
  3. Return 1;
  4. Else
  5. Return func1(m-1,n-1) + n*func1(m-1,n);
  6. }
The thing is I can’t find this anywhere in my text book, and I haven’t had any algebra in 10 years. (if it is indeed algebra and I'm going off on a tangent) If you walk me thru it, don't use the values of 5, 3 because I don't want the answer.
Thank you
Why don't you walk us through what you think first and then people can correct you if you are wrong.
Nov 1 '06 #2
OK, the first part is easy if both values equal each other or the second value equals 1 than "1" is returned until some other values are inputed until the "else" is run.
So lets say the values are 4 and 2
(m-1,n-1) + n*func1(m-1,n)
(3,1) + 2*func1(3,2)
since there's no space between the comas which isn't normally done in Java, I assume the're multiplied.
(3) + 2*func1(6)
(3) + 2*4, 2(6)
(3) + 8 , 12
11 ,12
23 ?
Nov 1 '06 #3
r035198x
13,262 8TB
OK, the first part is easy if both values equal each other or the second value equals 1 than "1" is returned until some other values are inputed until the "else" is run.
So lets say the values are 4 and 2
(m-1,n-1) + n*func1(m-1,n)
(3,1) + 2*func1(3,2)
since there's no space between the comas which isn't normally done in Java, I assume the're multiplied.
(3) + 2*func1(6)
(3) + 2*4, 2(6)
(3) + 8 , 12
11 ,12
23 ?
You need to look at a recursion tutorial.
In func1(3,1) + 2*func1(3,2), 3 and 1 are not multiplied together. func1(3, 1) means call the function func1 with values 3 and 1.

func1(3, 1) + 2*(func1(3, 2))

now for func1(3, 1), n == 1
so func1(3, 1) = 1

You now have

1 + 2*(func1(2, 1) + 2*(func1(2, 2))

Which you should now see is

1 + 2*(1 + 2*(func1(1, 1) + 2*(func1(1, 2))))

= 1 + 2*(1 + 2 + 2)
Nov 2 '06 #4
Thanks for the help. That makes sense. I figured I was going down the wrong path. My text book touches on recursion briefly, but never had any examples like the one depicted.
Nov 2 '06 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: lallous | last post by:
file: prog1.cpp #include <stdio.h> #include "temp1.h" int main() { double d; Templ1::func(d); return 0; }
14
by: mikets | last post by:
Hi there, I found out that very often I use the following construct: for (it = myvec.begin(); it != myvec.end(); ++it) { if (it->name() == "myname") break; } Certainly, the container the...
4
by: CoolPint | last post by:
I would be grateful if someone could point out if I am understanding correctly and suggest ways to improve. Sorry for the long message and I hope you will kindly bear with it. I have to make it...
4
by: xuatla | last post by:
Hi, I have a class class myType { private: int size; double *elem; .....
5
by: xuatla | last post by:
Hi, I have the following code for function pointer. compiling is ok. Can you help me to check whether it's a good way to implement as: class CA { ..... private: void f1( double ) ;
6
by: ooze | last post by:
In the unix like system, there is a func ptr signal defined as below at the last line ,but I don't know how to understand it. becoz the more general to define a func ptr is the following void...
4
by: sublimanized | last post by:
Hello all ... here is my problem. I just got the book "Teach Yourself C ++ in 21 Days" Setup: Fedora Core 6 - i386 GCC 4.1.1 Again, I am a complete newcomer to C++, and this is one of the...
0
by: Mitko Haralanov | last post by:
I am attempting to get a working wrapper around the TransactionSet class from the rpm module but I am getting unexplained segfaults in /usr/bin/python. The reason why I am working on a wrapper...
3
by: Dameon99 | last post by:
Hi.. Im experiencing a weird error I dont know how to fix. I have a scanner object and whenever I use nextInt, anything above 3 causes the program to crash saying and links me to this line of the...
1
by: nigelesquire | last post by:
I am in need of your assistance. I have a page with multiple unixtime stamps and I need to display them in readable time and date with the user's time zone. Below is the code. <!DOCTYPE...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.