Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › help with c - complex #s and powers
New Posts  All Forums:Forum Nav:

help with c - complex #s and powers

post #1 of 10
Thread Starter 
ok so ive got a little homework assignment, had to make 7 programs. add, substract, multiply and divide complex numbers, also finding the module, multiplying by an scalar number and finally, elevating a complex number to a power. So Ive done the first six with a little bit of work. Now im stuck on the last one... can anyone help me a bit? note: i cant use <complex.h>.
Gobalr
(13 items)
 
  
CPUMotherboardGraphicsRAM
Core 2 Duo E7400 @ 3.5 Gigabyte GA-P35-DS3L Rev. 2.0 MSI 8600 GT Silent Edition (720/967/1754) 4GB G.Skill DDR2 1066 
Hard DriveOptical DriveOSMonitor
250GB Samsung & 80GB Maxtor Samsung DVD-RW & Pioneer CD-RW Windows 7 22w HP & 17w Viewsonic 
KeyboardPowerCaseMouse
Genius KB600 400W Acteck Rosewill R5717-P SL Genius KB600 
Mouse Pad
None 
  hide details  
Reply
Gobalr
(13 items)
 
  
CPUMotherboardGraphicsRAM
Core 2 Duo E7400 @ 3.5 Gigabyte GA-P35-DS3L Rev. 2.0 MSI 8600 GT Silent Edition (720/967/1754) 4GB G.Skill DDR2 1066 
Hard DriveOptical DriveOSMonitor
250GB Samsung & 80GB Maxtor Samsung DVD-RW & Pioneer CD-RW Windows 7 22w HP & 17w Viewsonic 
KeyboardPowerCaseMouse
Genius KB600 400W Acteck Rosewill R5717-P SL Genius KB600 
Mouse Pad
None 
  hide details  
Reply
post #2 of 10
So you need to know how to bring it to a power?
Lee XT
(17 items)
 
  
CPUMotherboardGraphicsRAM
AMD FX-6300 Asus M5A97 SAPPHIRE Radeon HD 7850 AMD 4GB DDR3 1333MHZ 
RAMRAMRAMHard Drive
AMD 4GB DDR3 1333MHZ AMD 4GB DDR3 1333MHZ AMD 4GB DDR3 1333MHZ OCZ Vertex 4 256GB 
CoolingOSMonitorKeyboard
Corsair H80 Windows 8.1 Pro MCE Dell P2414H WHXV7  Microsoft Generic 
PowerCaseMouseMouse Pad
Ultra 600W Limited Edition NZXT Black Steel Razer Deathadder Razer Goliath 
Audio
Realtek HD Audio 
  hide details  
Reply
Lee XT
(17 items)
 
  
CPUMotherboardGraphicsRAM
AMD FX-6300 Asus M5A97 SAPPHIRE Radeon HD 7850 AMD 4GB DDR3 1333MHZ 
RAMRAMRAMHard Drive
AMD 4GB DDR3 1333MHZ AMD 4GB DDR3 1333MHZ AMD 4GB DDR3 1333MHZ OCZ Vertex 4 256GB 
CoolingOSMonitorKeyboard
Corsair H80 Windows 8.1 Pro MCE Dell P2414H WHXV7  Microsoft Generic 
PowerCaseMouseMouse Pad
Ultra 600W Limited Edition NZXT Black Steel Razer Deathadder Razer Goliath 
Audio
Realtek HD Audio 
  hide details  
Reply
post #3 of 10
Thread Starter 
yup
Gobalr
(13 items)
 
  
CPUMotherboardGraphicsRAM
Core 2 Duo E7400 @ 3.5 Gigabyte GA-P35-DS3L Rev. 2.0 MSI 8600 GT Silent Edition (720/967/1754) 4GB G.Skill DDR2 1066 
Hard DriveOptical DriveOSMonitor
250GB Samsung & 80GB Maxtor Samsung DVD-RW & Pioneer CD-RW Windows 7 22w HP & 17w Viewsonic 
KeyboardPowerCaseMouse
Genius KB600 400W Acteck Rosewill R5717-P SL Genius KB600 
Mouse Pad
None 
  hide details  
Reply
Gobalr
(13 items)
 
  
CPUMotherboardGraphicsRAM
Core 2 Duo E7400 @ 3.5 Gigabyte GA-P35-DS3L Rev. 2.0 MSI 8600 GT Silent Edition (720/967/1754) 4GB G.Skill DDR2 1066 
Hard DriveOptical DriveOSMonitor
250GB Samsung & 80GB Maxtor Samsung DVD-RW & Pioneer CD-RW Windows 7 22w HP & 17w Viewsonic 
KeyboardPowerCaseMouse
Genius KB600 400W Acteck Rosewill R5717-P SL Genius KB600 
Mouse Pad
None 
  hide details  
Reply
post #4 of 10
Quote:
Originally Posted by gobalr View Post
yup
Cheapest way to do this (since i have almost no knowledge of C) would be a loop.

Code:
for(int i;i < <power here>;i++)
{
<variable> *= <variable>;
}
Again i have limited C knowledge. I would suggest making a function for this, call it extra credit. Of course i am pretty sure the language has a built in function for this, however i don't know how to call it.
Lee XT
(17 items)
 
  
CPUMotherboardGraphicsRAM
AMD FX-6300 Asus M5A97 SAPPHIRE Radeon HD 7850 AMD 4GB DDR3 1333MHZ 
RAMRAMRAMHard Drive
AMD 4GB DDR3 1333MHZ AMD 4GB DDR3 1333MHZ AMD 4GB DDR3 1333MHZ OCZ Vertex 4 256GB 
CoolingOSMonitorKeyboard
Corsair H80 Windows 8.1 Pro MCE Dell P2414H WHXV7  Microsoft Generic 
PowerCaseMouseMouse Pad
Ultra 600W Limited Edition NZXT Black Steel Razer Deathadder Razer Goliath 
Audio
Realtek HD Audio 
  hide details  
Reply
Lee XT
(17 items)
 
  
CPUMotherboardGraphicsRAM
AMD FX-6300 Asus M5A97 SAPPHIRE Radeon HD 7850 AMD 4GB DDR3 1333MHZ 
RAMRAMRAMHard Drive
AMD 4GB DDR3 1333MHZ AMD 4GB DDR3 1333MHZ AMD 4GB DDR3 1333MHZ OCZ Vertex 4 256GB 
CoolingOSMonitorKeyboard
Corsair H80 Windows 8.1 Pro MCE Dell P2414H WHXV7  Microsoft Generic 
PowerCaseMouseMouse Pad
Ultra 600W Limited Edition NZXT Black Steel Razer Deathadder Razer Goliath 
Audio
Realtek HD Audio 
  hide details  
Reply
post #5 of 10
Thread Starter 
yes the language has a built in function for this, but im not allowed to use it...

wow had to read that a few times to get how i can implement it... i can basically just do the same operation as multiplying but inside a loop that marks the exponent... great!! thanks a lot
Gobalr
(13 items)
 
  
CPUMotherboardGraphicsRAM
Core 2 Duo E7400 @ 3.5 Gigabyte GA-P35-DS3L Rev. 2.0 MSI 8600 GT Silent Edition (720/967/1754) 4GB G.Skill DDR2 1066 
Hard DriveOptical DriveOSMonitor
250GB Samsung & 80GB Maxtor Samsung DVD-RW & Pioneer CD-RW Windows 7 22w HP & 17w Viewsonic 
KeyboardPowerCaseMouse
Genius KB600 400W Acteck Rosewill R5717-P SL Genius KB600 
Mouse Pad
None 
  hide details  
Reply
Gobalr
(13 items)
 
  
CPUMotherboardGraphicsRAM
Core 2 Duo E7400 @ 3.5 Gigabyte GA-P35-DS3L Rev. 2.0 MSI 8600 GT Silent Edition (720/967/1754) 4GB G.Skill DDR2 1066 
Hard DriveOptical DriveOSMonitor
250GB Samsung & 80GB Maxtor Samsung DVD-RW & Pioneer CD-RW Windows 7 22w HP & 17w Viewsonic 
KeyboardPowerCaseMouse
Genius KB600 400W Acteck Rosewill R5717-P SL Genius KB600 
Mouse Pad
None 
  hide details  
Reply
post #6 of 10
Quote:
Originally Posted by gobalr View Post
yes the language has a built in function for this, but im not allowed to use it...

wow had to read that a few times to get how i can implement it... i can basically just do the same operation as multiplying but inside a loop that marks the exponent... great!! thanks a lot
No problem, it was a simple task.
Lee XT
(17 items)
 
  
CPUMotherboardGraphicsRAM
AMD FX-6300 Asus M5A97 SAPPHIRE Radeon HD 7850 AMD 4GB DDR3 1333MHZ 
RAMRAMRAMHard Drive
AMD 4GB DDR3 1333MHZ AMD 4GB DDR3 1333MHZ AMD 4GB DDR3 1333MHZ OCZ Vertex 4 256GB 
CoolingOSMonitorKeyboard
Corsair H80 Windows 8.1 Pro MCE Dell P2414H WHXV7  Microsoft Generic 
PowerCaseMouseMouse Pad
Ultra 600W Limited Edition NZXT Black Steel Razer Deathadder Razer Goliath 
Audio
Realtek HD Audio 
  hide details  
Reply
Lee XT
(17 items)
 
  
CPUMotherboardGraphicsRAM
AMD FX-6300 Asus M5A97 SAPPHIRE Radeon HD 7850 AMD 4GB DDR3 1333MHZ 
RAMRAMRAMHard Drive
AMD 4GB DDR3 1333MHZ AMD 4GB DDR3 1333MHZ AMD 4GB DDR3 1333MHZ OCZ Vertex 4 256GB 
CoolingOSMonitorKeyboard
Corsair H80 Windows 8.1 Pro MCE Dell P2414H WHXV7  Microsoft Generic 
PowerCaseMouseMouse Pad
Ultra 600W Limited Edition NZXT Black Steel Razer Deathadder Razer Goliath 
Audio
Realtek HD Audio 
  hide details  
Reply
post #7 of 10
Hate to double post but i made a mistake.

Code:
for(int i;i <= <power here>;i++)
{
<variable> *= <variable>;
}
<= was the issue.
Lee XT
(17 items)
 
  
CPUMotherboardGraphicsRAM
AMD FX-6300 Asus M5A97 SAPPHIRE Radeon HD 7850 AMD 4GB DDR3 1333MHZ 
RAMRAMRAMHard Drive
AMD 4GB DDR3 1333MHZ AMD 4GB DDR3 1333MHZ AMD 4GB DDR3 1333MHZ OCZ Vertex 4 256GB 
CoolingOSMonitorKeyboard
Corsair H80 Windows 8.1 Pro MCE Dell P2414H WHXV7  Microsoft Generic 
PowerCaseMouseMouse Pad
Ultra 600W Limited Edition NZXT Black Steel Razer Deathadder Razer Goliath 
Audio
Realtek HD Audio 
  hide details  
Reply
Lee XT
(17 items)
 
  
CPUMotherboardGraphicsRAM
AMD FX-6300 Asus M5A97 SAPPHIRE Radeon HD 7850 AMD 4GB DDR3 1333MHZ 
RAMRAMRAMHard Drive
AMD 4GB DDR3 1333MHZ AMD 4GB DDR3 1333MHZ AMD 4GB DDR3 1333MHZ OCZ Vertex 4 256GB 
CoolingOSMonitorKeyboard
Corsair H80 Windows 8.1 Pro MCE Dell P2414H WHXV7  Microsoft Generic 
PowerCaseMouseMouse Pad
Ultra 600W Limited Edition NZXT Black Steel Razer Deathadder Razer Goliath 
Audio
Realtek HD Audio 
  hide details  
Reply
post #8 of 10
Thread Starter 
dont worry, all i needed was the idea for the loop. now, im programing it and ran into a few problems that im fixing. since im doing the loop i cant do say an exponent equal to 0 since it should equal 1, but in the program it skips the loop. so im putting a few if statements to make sure if power=0 then result=1, if power=1 then result=same number, etc.
thing is, im having trouble im my if statements, here they are maybe you can tell me whats wrong
Quote:
{ comp z; int i;
if (p==0)
{z.real=1;
z.imag=0;}
else if (p==1)
{ z.real=x.real;
z.imag=x.imag; }
else
{
for (i=0; i<=p; i++)
{
z.real=(x.real*x.real)-(x.imag*x.imag);
z.imag=(x.imag*x.real)+(x.real*x.imag);
}}
return z; }
comp is defined already


EDIT: ok nevermind, i found the mistake. i was scanning "p" which is the power as a double when i defined it as a interger
Gobalr
(13 items)
 
  
CPUMotherboardGraphicsRAM
Core 2 Duo E7400 @ 3.5 Gigabyte GA-P35-DS3L Rev. 2.0 MSI 8600 GT Silent Edition (720/967/1754) 4GB G.Skill DDR2 1066 
Hard DriveOptical DriveOSMonitor
250GB Samsung & 80GB Maxtor Samsung DVD-RW & Pioneer CD-RW Windows 7 22w HP & 17w Viewsonic 
KeyboardPowerCaseMouse
Genius KB600 400W Acteck Rosewill R5717-P SL Genius KB600 
Mouse Pad
None 
  hide details  
Reply
Gobalr
(13 items)
 
  
CPUMotherboardGraphicsRAM
Core 2 Duo E7400 @ 3.5 Gigabyte GA-P35-DS3L Rev. 2.0 MSI 8600 GT Silent Edition (720/967/1754) 4GB G.Skill DDR2 1066 
Hard DriveOptical DriveOSMonitor
250GB Samsung & 80GB Maxtor Samsung DVD-RW & Pioneer CD-RW Windows 7 22w HP & 17w Viewsonic 
KeyboardPowerCaseMouse
Genius KB600 400W Acteck Rosewill R5717-P SL Genius KB600 
Mouse Pad
None 
  hide details  
Reply
post #9 of 10
Quote:
Originally Posted by gobalr View Post
dont worry, all i needed was the idea for the loop. now, im programing it and ran into a few problems that im fixing. since im doing the loop i cant do say an exponent equal to 0 since it should equal 1, but in the program it skips the loop. so im putting a few if statements to make sure if power=0 then result=1, if power=1 then result=same number, etc.
thing is, im having trouble im my if statements, here they are maybe you can tell me whats wrong


comp is defined already


EDIT: ok nevermind, i found the mistake. i was scanning "p" which is the power as a double when i defined it as a interger
Ok so you are good to go?
Lee XT
(17 items)
 
  
CPUMotherboardGraphicsRAM
AMD FX-6300 Asus M5A97 SAPPHIRE Radeon HD 7850 AMD 4GB DDR3 1333MHZ 
RAMRAMRAMHard Drive
AMD 4GB DDR3 1333MHZ AMD 4GB DDR3 1333MHZ AMD 4GB DDR3 1333MHZ OCZ Vertex 4 256GB 
CoolingOSMonitorKeyboard
Corsair H80 Windows 8.1 Pro MCE Dell P2414H WHXV7  Microsoft Generic 
PowerCaseMouseMouse Pad
Ultra 600W Limited Edition NZXT Black Steel Razer Deathadder Razer Goliath 
Audio
Realtek HD Audio 
  hide details  
Reply
Lee XT
(17 items)
 
  
CPUMotherboardGraphicsRAM
AMD FX-6300 Asus M5A97 SAPPHIRE Radeon HD 7850 AMD 4GB DDR3 1333MHZ 
RAMRAMRAMHard Drive
AMD 4GB DDR3 1333MHZ AMD 4GB DDR3 1333MHZ AMD 4GB DDR3 1333MHZ OCZ Vertex 4 256GB 
CoolingOSMonitorKeyboard
Corsair H80 Windows 8.1 Pro MCE Dell P2414H WHXV7  Microsoft Generic 
PowerCaseMouseMouse Pad
Ultra 600W Limited Edition NZXT Black Steel Razer Deathadder Razer Goliath 
Audio
Realtek HD Audio 
  hide details  
Reply
post #10 of 10
Thread Starter 
thought so till i tried a power greater than 2 =) tried 99 and program gave me 0+800i
but i just gotta fix a few small details maybe tomorrow, got till monday anyways. thanks a lot for the help

EDIT:ok, turns out it wasnt a problem with the program, thats just the way its suppossed to be... so im finally done. thanks
Gobalr
(13 items)
 
  
CPUMotherboardGraphicsRAM
Core 2 Duo E7400 @ 3.5 Gigabyte GA-P35-DS3L Rev. 2.0 MSI 8600 GT Silent Edition (720/967/1754) 4GB G.Skill DDR2 1066 
Hard DriveOptical DriveOSMonitor
250GB Samsung & 80GB Maxtor Samsung DVD-RW & Pioneer CD-RW Windows 7 22w HP & 17w Viewsonic 
KeyboardPowerCaseMouse
Genius KB600 400W Acteck Rosewill R5717-P SL Genius KB600 
Mouse Pad
None 
  hide details  
Reply
Gobalr
(13 items)
 
  
CPUMotherboardGraphicsRAM
Core 2 Duo E7400 @ 3.5 Gigabyte GA-P35-DS3L Rev. 2.0 MSI 8600 GT Silent Edition (720/967/1754) 4GB G.Skill DDR2 1066 
Hard DriveOptical DriveOSMonitor
250GB Samsung & 80GB Maxtor Samsung DVD-RW & Pioneer CD-RW Windows 7 22w HP & 17w Viewsonic 
KeyboardPowerCaseMouse
Genius KB600 400W Acteck Rosewill R5717-P SL Genius KB600 
Mouse Pad
None 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › help with c - complex #s and powers