Register and join over 40,000 other developers!
Recent Topics

Print specific values from dictionary with a specific key name
Siten0308  Jun 20 2019 01:43 PM

Learn algorithms and programming concepts
johnnylo  Apr 23 2019 07:49 AM

Job Gig PHP Form Needed
PJohnson  Apr 18 2019 03:55 AM

How to make code run differently depending on the platform it is running on?
xarzu  Apr 05 2019 09:17 AM

How do I set a breakpoint in an attached process in visual studio
xarzu  Apr 04 2019 11:47 AM
Recent Blog Entries
Recent Status Updates
Popular Tags
 networking
 Managed C++
 stream
 console
 database
 authentication
 Visual Basic 4 / 5 / 6
 session
 Connection
 asp.net
 import
 syntax
 hardware
 html5
 array
 mysql
 java
 php
 c++
 string
 C#
 html
 loop
 timer
 jquery
 ajax
 javascript
 programming
 android
 css
 assembly
 c
 form
 vb.net
 xml
 linked list
 login
 encryption
 pseudocode
 calculator
 sql
 python
 setup
 help
 game
 combobox
 binary
 hello world
 grid
 innerHTML
4 replies to this topic
#1
Posted 30 November 2007  09:39 AM
i just began programming in C++ i kno all the basics..
i am trying to code a factorization program..
Ax^2 + Bx + c = 0.
if you guys remember in high school algebra that you have to find two numbers that multiply to be c * A and also add up to be B. i ask the user for the A,B,C values.
i am stuck in finding the two numbers that would be c * A.
for this to happen i use a for loop ranging values are
for (x =1; x <50000 ; x++)
this will create the first number
for (y=1; y<5000; y++)
this will create the second.
the only problem is i do not know how to nest it right so x stays the same until y reaches 5000 then x changes to the next number.
i also used the if statement to determine when x * y = product(c*A).
thanks for reading please help all you can
thank you!
i am trying to code a factorization program..
Ax^2 + Bx + c = 0.
if you guys remember in high school algebra that you have to find two numbers that multiply to be c * A and also add up to be B. i ask the user for the A,B,C values.
i am stuck in finding the two numbers that would be c * A.
for this to happen i use a for loop ranging values are
for (x =1; x <50000 ; x++)
this will create the first number
for (y=1; y<5000; y++)
this will create the second.
the only problem is i do not know how to nest it right so x stays the same until y reaches 5000 then x changes to the next number.
i also used the if statement to determine when x * y = product(c*A).
thanks for reading please help all you can
thank you!
#2
Posted 30 November 2007  06:12 PM
Use the math rules for factorization, and implement it into your program, try a better algorithm, find the number where the conditions are good, not needed to use a constant as 50000
for example if your equation is: x2 + 5x + 6 the rule is simple
W1 and W2 where the constants that multiply to get A
A=W1 * W2
C=Z1 * Z2
and B=W1*Z2 + W2 *Z1 the hard part is to get W1,W2,Z1,Z2 but is easy, is just the matter to find the numbers, the multiplies must be smaller than the number, for example, W1 and W2 must be smaller than A and also Z1 and Z2 must be smaller than C so you can start your tests.
for example if your equation is: x2 + 5x + 6 the rule is simple
W1 and W2 where the constants that multiply to get A
A=W1 * W2
C=Z1 * Z2
and B=W1*Z2 + W2 *Z1 the hard part is to get W1,W2,Z1,Z2 but is easy, is just the matter to find the numbers, the multiplies must be smaller than the number, for example, W1 and W2 must be smaller than A and also Z1 and Z2 must be smaller than C so you can start your tests.
#3
Posted 30 November 2007  10:14 PM
nice explanation.. thanks for the help man.. i m going to have to think some codin sense in to me i
will update thanks..
will update thanks..
#4
Posted 01 December 2007  06:19 AM
If i understand your problem correct,there is a simplier way.
You want to find 2 numbers that solves the situation.
also for these numbers x1 and x2 issues x1*x2=c*a and x1+x2=b.
Well try this.
Define D=b^24*a*c
Then you have x1=(b+ ?D)/2a and x2=(b ?d)/2a
where ?D i mean ?25 = 5
an example 2x^2+5x+2=0
D=252*4*2=2516=9
then x1=(5+3)/2*2=0.5
and x2=(53)/2*2=2
well if D=0 then x1=x2
and if D<0 then there is no real number to match.
Well i think it is much easier to programming it now.
Send me to mali21nick@gmail.com what you succeed.
You want to find 2 numbers that solves the situation.
also for these numbers x1 and x2 issues x1*x2=c*a and x1+x2=b.
Well try this.
Define D=b^24*a*c
Then you have x1=(b+ ?D)/2a and x2=(b ?d)/2a
where ?D i mean ?25 = 5
an example 2x^2+5x+2=0
D=252*4*2=2516=9
then x1=(5+3)/2*2=0.5
and x2=(53)/2*2=2
well if D=0 then x1=x2
and if D<0 then there is no real number to match.
Well i think it is much easier to programming it now.
Send me to mali21nick@gmail.com what you succeed.
#5
Posted 03 December 2007  08:54 AM
for (x=1;x<sqrt(a*c);x++) { if (a*c) % x = 0 then { if (a*c)/x + x = b then { cout<<x<<" "<<(a*c)/x; x=a*c; } } }
Programming is a branch of mathematics.
My CodeCall Blog  My Personal Blog
My MineCraft server site: http://banishedwings.enjin.com/
Also tagged with one or more of these keywords: for loop, loop
Language Forums →
PHP →
Content and title won't show on certain page in WordpressStarted by Mello, 05 Jan 2016 wordpress, php, loop 


Answered
Language Forums →
Java →
Average does not calculate after For LoopStarted by dreddooo, 22 Apr 2015 java, loops, for loop 


Language Forums →
C# →
Create Staircase with Nested LoopsStarted by StainedSilva, 12 Mar 2015 nested, loop, staircase 


Language Forums →
Other Languages →
Bash / Shell Scripting →
Here is a task... Find Nothing :PStarted by ShaunPrawn, 07 Aug 2014 random, bash, loop, number and 1 more... 


General Forums →
General Programming →
Trying to do a working loopStarted by Error, 23 Jun 2014 loop, java 

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download