Write a c program to add two complex numbers, C/C++ Programming

Assignment Help:

  #include stdio.h
  struct  complex
  {
  float real;
  float imag;
  };
  struct complex complexadd(struct complex,struct  complex);
  void main()
    {
   
     Date: 26th August 1992 
    Version 1.0 
    Function : To add two complex numbers to gether uses function
         complecxaddd

     /* Define two complex numbers */
  char prompt;
  struct  complex z1,z2,z3;
  printf("Please enter in number 1  a+jb ");
  printf(" \n\rEnter in the real part of a =  ");
  scanf("%f",&(z1.real));
  printf(" \n\rEnter in the complex part of b =  ");
  scanf("%f",&(z1.imag));
  printf("Please enter in number 2  a+jb ");
  printf(" \n\rEnter in the real part of a =  ");
  scanf("%f",&(z2.real));
  printf(" \n\rEnter in the complex part of b = ");
  scanf("%f",&(z2.imag));
  z3 = complexadd(z1,z2);
  printf("\n\rThe solution is a+jb where a = %f and b = %f   ",z3.real,z3.imag);
  printf("Press and key to exit \n\r");
  scanf("\n%c",&prompt);
  }
 
struct complex complexadd(struct complex a1, struct complex b1)
  {

     Date: 26th August 1992 
    Version 1.0 
    Function : Add two complex structures together and returns the answer as a complex structure       
     Modifications:   none*/
 
  struct complex result;
  /* Add the real parts together */
  result.real = a1.real + b1.real;
  /* add the imaginary parts together */
  result.imag = a1.imag + b1.imag;
  return(result);
  }
 
Good functions should return back also a status indicating whether it has passed or failed, look at scanf and string functions etc.


Related Discussions:- Write a c program to add two complex numbers

#title.jewel polish., Ask questionByteland county is very famous for lumino...

Ask questionByteland county is very famous for luminous jewels. Luminous jewels are used in making beautiful necklaces. A necklace consists of various luminous jewels of particular

Program to create a digital clock, Create a C language code, only one progr...

Create a C language code, only one program, to implement the following task. Task: Write C code for a program that implements a digital clock (HH:MM:SS). The clock inclu

Use of a windows box, This program requires the use of a windows box, no co...

This program requires the use of a windows box, no console applications are allowed. Prepare for Christmas now.  Each year, Reindeer Gift Emporium publishes a Christmas price list

Serial programming, Hi I''m trying to connect to CISCO router using termios...

Hi I''m trying to connect to CISCO router using termios. So I decided to have two threads one for reading data and the other one for writing data. The problem is that I have to add

Give example of the do while loop, Normal 0 false false fal...

Normal 0 false false false EN-IN X-NONE X-NONE MicrosoftInternetExplorer4

C program to add, C program to add, average and deviation of numbers: v...

C program to add, average and deviation of numbers: void main() {                 int sum=0,a[10],i;                 float avg=0,dev,vari=0,var;                 pri

Define commonly used built-in library functions, Define Commonly Used Built...

Define Commonly Used Built-in Library Functions? Comprise opened a file pointer you will desire to use it for either input or output. The C language supplies a set of functions

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd