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

Load catalogue from file, Implement a menu driven real estate catalogue sys...

Implement a menu driven real estate catalogue system that allows users to perform various catalogue maintenance and search tasks.  You are only allowed to use the C programming la

Write a c program to input three real numbers, Write a C program to input f...

Write a C program to input five numbers and print them out on a new line Write a C program to input three real numbers and print them out as follows:   The first variable is

Create a class string which stores a string value, Question 1 Write a prog...

Question 1 Write a program that accepts two numbers from the user and swaps the two numbers without using a temporary variable Question 2 Write a program that accepts a 3x

Using c language, I have a program and I want someone to fix it for me by u...

I have a program and I want someone to fix it for me by using basic c language program.

Explain static class members, Static Class Members As we already know a...

Static Class Members As we already know all the objects of the class have dissimilar data members but invoke the similar member functions. Though, there is an exception to this

Tells the operators one can override; which operators , Q:  Tells the opera...

Q:  Tells the operators one can override; which operators should he override? A: Bottom line: don't puzzle your users. Remember the reason of operator overloading: to decreas

Write a recursive implementation of euclid algorithm, Write a recursive imp...

Write a recursive implementation of Euclid's algorithm for finding the greatest common divisor (GCD) of two integers. Descriptions of this algorithm are available in algebra books

Minimum shelves, write a program to find the minimum number of shelves

write a program to find the minimum number of shelves

Queue - c++ program, Queue - C++ program: Write a program to show the ...

Queue - C++ program: Write a program to show the basic operations on queue. namespace stack {  const int max_size = 200;  char v(max_size);  int top=0;  void pu

Write a program that predicts users age, Write a program that predicts user...

Write a program that predicts users age: Write a program that predicts users' age (0-128 years old) with at most 7 questions. The game starts with asking the user whether he/s

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