Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
1. Define a C structure complx for a complex number with two data
members for the (real, imaginary) of the complex number. It should handle any real numbers! Use typedef to make your program readable.
2.write a procedure to raise any complex number to any integer power (π‘₯ + 𝑗𝑦)^n
Where π‘₯ and 𝑦 are real number and 𝑛 is an integer!
3.write (π‘₯ + 𝑗𝑦)π‘Žπ‘  𝑅e^π‘—πœƒ where 𝑅 = √(π‘₯^2 + 𝑦^2) π‘Žπ‘›π‘‘ tan^βˆ’1(πœƒ) = (𝑦/π‘₯)
4. Then write (π‘₯ + 𝑗𝑦)^𝑛 π‘Žπ‘  𝑅^𝑛*𝑒^π‘—π‘›πœƒ and go back to write the result as 𝑅^𝑛*𝑒^π‘—π‘›πœƒ π‘Žπ‘  (𝑅^𝑛*π‘π‘œπ‘ (π‘›πœƒ) + 𝑗𝑅^𝑛*𝑠𝑖𝑛(π‘›πœƒ))
5. In your procedure (function) you will use for-loop to compute the value
of 𝑅^𝑛. Write programs to compute the 𝑠𝑖𝑛(π‘₯) π‘Žπ‘›π‘‘ π‘π‘œπ‘ (π‘₯) functions. You may
use the math library header file and use the trig functions
[𝑠𝑖𝑛( ) , π‘π‘œπ‘ ( ) π‘Žπ‘›π‘‘ π‘‘π‘Žπ‘›( )] and the square-root functions only!
6. Note that the π‘‘π‘Žπ‘›(π‘₯) is multi-valued. check if it is in the fourth quadrant
7. The function should print the result on the screen in the form
Ans: ( x, jy)and return the function to main()

What I have tried:

#include<complex.h>
#include<mathlib.h>
typedef struct complex
{
float real,imag;
}
int main()
{
Posted
Updated 17-May-21 21:29pm

Start with some C tutorial to learn coding. You MUST understand the mathematical theory of your task to write it in code.

tips:
- install Visual Studio to have an excellent IDE
- give explaining names to all code pieces and write some comments
- use functions and structs to seperate tasks and data
- make a lot of printf output
- use the debugger
 
Share this answer
 
Well, your struct is a (little) start. You know, you can raise a complex number by iterative multiplication by itself[^].
I give you an example
C++
#include <iostream>
using namespace std;

struct complex
{
  double re;
  double im;
};


ostream & operator << (ostream & os, const complex & c)
{
  os << c.re << "+" << c.im << "j ";
  return os;
}

complex complex_multiply( const complex & factor1, const complex & factor2)
{
  complex result;
  result.re = factor1.re * factor2.re - factor1.im * factor2.im;
  result.im = factor1.re * factor2.im + factor1.im * factor2.re;
  return result;
}

int main()
{
  complex c{1,1};

  cout << "c=" << c << ", c^2 = " << complex_multiply(c,c) << endl;
}


Completing the exercises, now, is up to you.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900