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...

  • 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...

  • 5. A complex number consists of two components: the real component and the imaginary component. A...

    C++ //add as many comments as possible 5. A complex number consists of two components: the real component and the imaginary component. An example of a complex number is 2+3i, where 2 is the real component and 3 is the imaginary component of the data. Define a class MyComplexClass. It has two data values of float type: real and imaginary This class has the following member functions A default constructor that assigns 0.0 to both its real and imaginary data...

  • A complex number is a number of the form a + bi, where a and b...

    A complex number is a number of the form a + bi, where a and b are real numbers √ and i is −1. The numbers a and b are known as the real and the imaginary parts, respectively, of the complex number. The operations addition, subtraction, multiplication, and division for complex num- bers are defined as follows: (a+bi)+(c+di) = (a+c)+(b+d)i (a+bi)−(c+di) = (a−c)+(b−d)i (a + bi) ∗ (c + di) = (ac − bd) + (bc + ad)i (a...

  • Define a type which comprises a struct called "Maxima". In this struct contains two int values...

    Define a type which comprises a struct called "Maxima". In this struct contains two int values a and b. The purpose of this struct is to store the largest two int values among a set of integers. The value a is the largest number and the value b is the second largest number. In order to accomplish this task, you need to write the following functions: allzero( struct pointer ): This function sets a and b values in a given...

  • 12.24 HW2: Practice with Classes Objectives: Become familiar with developing a C++ class, to include developing:...

    12.24 HW2: Practice with Classes Objectives: Become familiar with developing a C++ class, to include developing: A constructor An multiplication operator A friend function (input operator) Introduce various C and C++ functions for parsing user input Assignment Details This assignment consists of 6 parts. Part 1: Using an IDE of your own choosing (Visual Studio is recommended), create a new project and copy the starter code ComplexNumber.h ComplexNumber.cpp and TestComplexNumber.cpp to this new project for developing and testing your solution....

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
ADVERTISEMENT