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

Plot an objects, write a C code that plots an object on the window and on t...

write a C code that plots an object on the window and on the user''s click of mouse on the window, the object starts rotating continuously until the user presses the mouse again

Car rental project, I need a project on car rental system using c programmi...

I need a project on car rental system using c programming only of college level

When i develop a destructor, When I develop a destructor, do I require to e...

When I develop a destructor, do I require to explicitly call the destructors for my member objects?

What is the difference among const char *mypointer &char *, What is the dif...

What is the difference among const char *myPointer and char *const myPointer?  A: Const char *myPointer is a non constant pointer to constant data; whereas char *const myPointer

C program to print l diagonal triangle, C program to print L diagonal trian...

C program to print L diagonal triangle: void main() {                 int i=0,j=0;                 int arr[rows][cols];                 for (i=0; i

C program for string operations, Aim: To implement a program for following...

Aim: To implement a program for following string operations: Length of String. String Concatenation. Substring (provide start index and length) Find character a

Data types, #question write a prog c & cpp

#question write a prog c & cpp

Fill an array of randomly generated integers, The task consists of two part...

The task consists of two parts which are both preferably implemented in one source file. Towards the end of this document you will find a code skeleton that you must assume. Start

PROGRAMMING, PROCEDUAL PROGRAMMING INTRODUCTION

PROCEDUAL PROGRAMMING INTRODUCTION

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