Write a programme in 'C'. Define a structure “complex” to read two complex numbers and perform addition, subtraction of these two complex num

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter5: Repetition Statements
Section5.3: Interactive While Loops
Problem 6E: (Conversion) a. Write a C++ program to convert meters to feet. The program should request the...
icon
Related questions
Question

1. Write a programme in 'C'. Define a structure “complex” to read two complex numbers and perform
addition, subtraction of these two complex numbers and display the result.


Code:


#include<stdio.h>
struct complex{
float real;
float img;
};
int main(){
struct complex c1,c2,add,sub;
printf("Enter a and b of the first complex number (a+ib) \n");
scanf(" %f %f",&c1.real,&c1.img);
printf("Enter a and b of the second complex number (a+ib) \n");
scanf(" %f %f",&c2.real,&c2.img);
add.real = c1.real+c2.real;
add.img = c1.img+c2.img;
sub.real = c1.real-c2.real;
sub.img = c1.img-c2.img;
printf("c1+c2 = %f + %fi\n",add.real,add.img);
if(sub.img<0) printf("c1-c2 = %f %fi",sub.real,sub.img);
else printf("c1-c2 = %f + %fi",sub.real,sub.img);
return 0;
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
ADT and Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr