Question

#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <math.h> struct _cplx double re, im; // the real and imaginary pa

Declare a complex number structure (e.g. Complex) consisting of two doubles: the real part and the imaginary part. Write fu

need the code in .c format

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#define _CRT_SECURE_NO_WARNING

#include<stdio.h>

#include<math.h>

struct _cplx
{

double re, im;

int x,y,n;

}c;

Complex CmplxInit(double re ,double im)

{

Complex z={re,im};

return z;

}

void CmlxPrint(complex z)

{

print("%.3f + %.3fi",z.re,z.im);

}

Complex CmplxAdd(Complex v,Complex w)

{

Complex z={v.re+w.re,v.im+w.im};

return z;

}

Complex CmplxScalarMul(int p,Complex v)

{

Complex z={v.re*a,v.im*a};

return z;

}

void CmplxMUL(Complex v,Complex w)

{

c.re= v.re*w.real - v.im*w.im;
c.im = a.img*b.real + a.real*b.img;

  if (c.im >= 0)
  printf("Multiplication of the complex numbers = %d + %di", c.re, c.im);
  else
  printf("Multiplication of the complex numbers = %d %di", c.re, c.im);

}

void CmplxDIV(Complex v,Complex w)

{
  if (w.re == 0 && w.im == 0)
  printf("Division by 0 + 0i isn't allowed.");
  else
  {
x = v.real*b.real + v.img*b.img;
y = v.img*b.real - v.real*b.img;
n = w.real*b.real + w.img*b.img;

  if (x%z == 0 && y%z == 0)
  {
  if (y/n >= 0)
  printf("Division of the complex numbers = %d + %di", x/n, y/n);
  else
  printf("Division of the complex numbers = %d %di", x/n, y/n);
  }
  else if (x%n == 0 && y%n != 0)
  {
  if (y/n >= 0)
  printf("Division of two complex numbers = %d + %d/%di", x/n, y, n);
  else
  printf("Division of two complex numbers = %d %d/%di", x/n, y, n);
  }
  else if (x%n != 0 && y%n == 0)
  {
  if (y/n >= 0)
  printf("Division of two complex numbers = %d/%d + %di", x, n, y/n);
  else
  printf("Division of two complex numbers = %d %d/%di", x, n, y/n);
  }
  else
  {
  if (y/z >= 0)
  printf("Division of two complex numbers = %d/%d + %d/%di",x, n, y, n);
  else
  printf("Division of two complex numbers = %d/%d %d/%di", x, n, y, n);
  }
  

}

int main()

{

int p;

Complex v,z,w,k,l,m;

v=CmplxInit(3, 4);

w=CmplxInit(2, 3);

z=CmplxAdd(v , w);

CmplxPrint(z);

Printf("\n\n");

l=CmplxMUL(v , w);

Printf("\n\n");

m=CmplxDIV(v , w);

Printf("\n\n");

printf("Enter the number for the scalar multiplication:");

scanf("%d",&p)

k=CmplxScalarMul(p,v);

CmplxPrint(k);

Printf("\n\n");

getchar();

return 0;

}

Add a comment
Know the answer?
Add Answer to:
need the code in .c format #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <math.h> struct _cplx double re,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Consider the following C struct that represents a complex number. struct complex {    double real;    double...

    Consider the following C struct that represents a complex number. struct complex {    double real;    double imaginary; }; (a) [20 points/5 points each] Change this struct into a class. Make the member variables private, and add the following to the class: A default constructor that initializes the real and imaginary parts to 0. A constructor that allows initialization of both real and imaginary parts to any double value. A public member function that returns the magnitude of the complex number....

  • Define a class named COMPLEX for complex numbers, which has two private data members of type...

    Define a class named COMPLEX for complex numbers, which has two private data members of type double (named real and imaginary) and the following public methods: 1- A default constructor which initializes the data members real and imaginary to zeros. 2- A constructor which takes two parameters of type double for initializing the data members real and imaginary. 3- A function "set" which takes two parameters of type double for changing the values of the data members real and imaginary....

  • MATLAB The z-transform of LTI systems can be expressed as a ratio of two polynomials in z-1 Also,...

    MATLAB The z-transform of LTI systems can be expressed as a ratio of two polynomials in z-1 Also, the rational z-transform can be written in factored form N-M) for z → H(G) = 0, the values of z are the zeros of the system for z = p2 → H(p) = oo, the values of z are the poles of the system Use MATLAB to graph Y() 1-242+2882 x(2) 1-0.8 -2 H(z) = 0,82-1 +0 642 Hints: e z: is...

  • Create the header file named “Complex.h” that contains the following class: The class Complex represents a...

    Create the header file named “Complex.h” that contains the following class: The class Complex represents a complex number which is a number of the form a + bi where a and b are real numbers and i2 = −1. The class should contain: Private double field named real. Private double field named imaginary. Public default constructor that assigns 1 to real and 0 to imaginary. Public overloaded constructor that takes a double as a parameter named real. It assigns real...

  • USING C++, write a simple class defining complex numbers USING the FRIEND function (READ BELOW) Write...

    USING C++, write a simple class defining complex numbers USING the FRIEND function (READ BELOW) Write a C++ defining a class for complex numbers. A complex number is a number of the form: a + b ∗ i , where, for our purposes, a and b are numbers of type double, and i is a number that represents the quantity √−1. You should represent a complex number here as two values of type double. You should name the variables real...

  • Design a class Complex for handling Complex numbers and include the following: _ real: a double...

    Design a class Complex for handling Complex numbers and include the following: _ real: a double _ imaginary: a double The class has the following member functions. a. A constructor initializing the number with default parameters. b. Getters and Setters of the class data members as given below _ void setReal(double r) _ double getReal()const _ void setImaginary(double i) _ double getImaginary() const d. Overload unary ! operator which returns true if the real and the imaginary parts are zero,...

  • C++ CLASS FOR DEFINING COMPLEX NUMBERS (READ BELOW) Write a C++ defining a class for complex...

    C++ CLASS FOR DEFINING COMPLEX NUMBERS (READ BELOW) Write a C++ defining a class for complex numbers. A complex number is a number of the form: a + b ∗ i , where, for our purposes, a and b are numbers of type double, and i is a number that represents the quantity √ −1. You should represent a complex number here as two values of type double. You should name the variables real and imaginary. You can call the...

  • C++ // Need to create a class which contains and operates on complex numbers. A complex...

    C++ // Need to create a class which contains and operates on complex numbers. A complex number is defined as “a number that can be expressed in the form a + bi, where a and b are real numbers, and i is imaginary” a is called the real part and b is called the imaginary part. The class MyComplexClass will store the complex number as separate real part and imaginary part values. MyComplexClass Private Member Variables *One double for the...

  • EXPLAIN HOW THIS PROGRAM WORKS, USING DEV C++ #include <iostream> #include <cmath> #define PI 3.1415926535897 using...

    EXPLAIN HOW THIS PROGRAM WORKS, USING DEV C++ #include <iostream> #include <cmath> #define PI 3.1415926535897 using namespace std; typedef struct ComplexRectStruct {    double real;    double imaginary; } ComplexRect; typedef struct ComplexPolarStruct {    double magnitude;    double angle; } ComplexPolar; double radToDegree (double rad) {    return (180.00 * rad) / PI; } double degToRadian (double deg) {    return (deg * PI) / 180; } ComplexPolar toPolar (ComplexRect r) {    ComplexPolar p;    p.magnitude = round(sqrt(pow(r.real,...

  • C++ Addition of Complex Numbers Background Knowledge A complex number can be written in the format of , where and are real numbers.   is the imaginary unit with the property of .   is called the r...

    C++ Addition of Complex Numbers Background Knowledge A complex number can be written in the format of , where and are real numbers.   is the imaginary unit with the property of .   is called the real part of the complex number and   is called the imaginary part of the complex number. The addition of two complex numbers will generate a new complex number. The addition is done by adding the real parts together (the result's real part) and adding the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT