How can I use C++ to solve the following problem?
List how many ways the numbers 9, 13, 17, 25, 31, and 35 can be added exactly 6 times to equal 100.
How can I use C++ to solve the following problem?
List how many ways the numbers 9, 13, 17, 25, 31, and 35 can be added exactly 6 times to equal 100.
Explain the problem more clearly.
Can the numbers be used more than once?
Yes, they can be. I thought about using an array and something with recursion, but I just can't figure it out.
Attempt to write some code and then post it. It is important you understand the problem first!!
Remember to use the code tags!!
Mr. C.
Think nested loops, an array and an if statement!
Free the weed!! Class B to class C is not good enough!!
And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi
Thanks for the help. It wasn't as hard as I thought it would be. ^^; I've been able to come up with the following so far:
I have two followup questions:Code:// points.cpp #include <iostream.h> int main() { int p[6] = {9,13,17,25,31,35}; int a, b, c, d, e, f, sum=0; for (a = 0; a < 6; a++) for (b = 0; b < 6; b++) for (c = 0; c < 6; c++) for (d = 0; d < 6; d++) for (e = 0; e < 6; e++) for (f = 0; f < 6; f++) { sum=p[a]+p[b]+p[c]+p[d]+p[e]+p[f]; if (sum == 100) cout << p[a] <<" + "<< p[b] <<" + "<< p[c] <<" + "<< p[d] <<" + "<< p[e] <<" + "<< p[f] <<" = 100" << endl; } return 0; }
1. How can I eliminate repeats? (ie: 35+25+9+9+9+13 and 35+25+9+9+13+9, and many others)
2. Is it possible to do the whole thing in one loop?
Last edited by Kaoru; 09-16-2002 at 01:17 PM.