MyWikiBiz, Author Your Legacy — Friday November 08, 2024
Jump to navigationJump to search
8 bytes added
, 17:32, 6 May 2008
Line 11: |
Line 11: |
| int main() | | int main() |
| { | | { |
− |
| |
| int A = 0; | | int A = 0; |
| int B = 0; | | int B = 0; |
Line 24: |
Line 23: |
| | | |
| double discrim = sqrt((B * B) - 4 * A * C); | | double discrim = sqrt((B * B) - 4 * A * C); |
− | double imaginary_discrim = sqrt(-((B * B) - 4 * A * C)); | + | double imaginary_discrim = sqrt(-((B * B) - (4 * A * C))); |
| | | |
− | if (discrim >= 0) | + | if(discrim >= 0) |
| { | | { |
| cout<<"The value of the discriminant is: "<<discrim<<"\n"; | | cout<<"The value of the discriminant is: "<<discrim<<"\n"; |
Line 37: |
Line 36: |
| if(A != 0) | | if(A != 0) |
| { | | { |
− | if(A <0) | + | if(A < 0) |
| { | | { |
| A *= -1; | | A *= -1; |
Line 45: |
Line 44: |
| { | | { |
| cout<<"When A = "<<A<<", B = "<<B<<", and C = "<<C<<", the two real solutions are:"<<"\n"; | | cout<<"When A = "<<A<<", B = "<<B<<", and C = "<<C<<", the two real solutions are:"<<"\n"; |
− | cout<<"X = "<<(-B + discrim)/(2.0 * A)<<"\n"; | + | cout<<"X = "<<((-B + discrim)/(2.0 * A))<<"\n"; |
− | cout<<"X = "<<(-B - discrim)/(2.0 * A)<<"\n"; | + | cout<<"X = "<<((-B - discrim)/(2.0 * A))<<"\n"; |
| } | | } |
| else if (discrim == 0) | | else if (discrim == 0) |
| { | | { |
| cout<<"When A = "<<A<<", B = "<<B<<", and C = "<<C<<", the one real solution is:"<<"\n"; | | cout<<"When A = "<<A<<", B = "<<B<<", and C = "<<C<<", the one real solution is:"<<"\n"; |
− | cout<<"X = "<<-B /(2.0 * A)<<"\n"; | + | cout<<"X = "<<(-B/(2.0 * A))<<"\n"; |
| } | | } |
| else | | else |
| { | | { |
| cout<<"When A = "<<A<<", B = "<<B<<", and C = "<<C<<", the two imaginary solutions are:"<<"\n"; | | cout<<"When A = "<<A<<", B = "<<B<<", and C = "<<C<<", the two imaginary solutions are:"<<"\n"; |
− | cout<<"X = "<<-B / (2.0 * A)<<" + "<<imaginary_discrim /(2 * A)<<"i"<<"\n"; | + | cout<<"X = "<<(-B/(2.0 * A))<<" + "<<(imaginary_discrim/(2 * A))<<"i"<<"\n"; |
− | cout<<"X = "<<-B / (2.0 * A)<<" - "<<imaginary_discrim /(2 * A)<<"i"<<"\n"; | + | cout<<"X = "<<(-B/(2.0 * A))<<" - "<<(imaginary_discrim/(2 * A))<<"i"<<"\n"; |
| } | | } |
| | | |