Telegram Group & Telegram Channel
141. WAP to multiply and add two complex numbers

Input :
5
-4
4
6

Output :
Sum is 9 + 2i
Product is 44 + 14i

#include<stdio.h>
#include<conio.h>

typedef struct {
int real;
int imag;
} complex;

void getdata (complex *);
void display (complex);
complex sum(complex,complex);
complex mult(complex,complex);

main() {
complex c1,c2,c3,c4;
getdata(&c1);
getdata(&c2);

c3=sum(c1,c2);
printf("Sum is ");
display(c3);

c4=mult(c1,c2);
printf("Product is ");
display(c4);

getch();
}

void getdata(complex *p) {
printf("Enter real ");
scanf("%d",&p->real);
printf("Enter imag ");
scanf("%d",&p->imag);
}

complex sum(complex c1,complex c2) {
complex t;
t.real=c1.real+c2.real;
t.imag=c1.imag+c2.imag;
return t;
}

complex mult(complex c1,complex c2) {
complex t;
t.real=c1.real*c2.real-c1.imag*c2.imag;
t.imag=c1.real*c2.imag+c2.real*c1.imag;
return t;
}

void display {
if(c.imag>=0)
printf("%d+%di\n",c.real,c.imag);
else
printf("%d%di\n",c.real,c.imag);
}
#program_by : @PLAUnit61398



tg-me.com/C_Codings/203
Create:
Last Update:

141. WAP to multiply and add two complex numbers

Input :
5
-4
4
6

Output :
Sum is 9 + 2i
Product is 44 + 14i

#include<stdio.h>
#include<conio.h>

typedef struct {
int real;
int imag;
} complex;

void getdata (complex *);
void display (complex);
complex sum(complex,complex);
complex mult(complex,complex);

main() {
complex c1,c2,c3,c4;
getdata(&c1);
getdata(&c2);

c3=sum(c1,c2);
printf("Sum is ");
display(c3);

c4=mult(c1,c2);
printf("Product is ");
display(c4);

getch();
}

void getdata(complex *p) {
printf("Enter real ");
scanf("%d",&p->real);
printf("Enter imag ");
scanf("%d",&p->imag);
}

complex sum(complex c1,complex c2) {
complex t;
t.real=c1.real+c2.real;
t.imag=c1.imag+c2.imag;
return t;
}

complex mult(complex c1,complex c2) {
complex t;
t.real=c1.real*c2.real-c1.imag*c2.imag;
t.imag=c1.real*c2.imag+c2.real*c1.imag;
return t;
}

void display {
if(c.imag>=0)
printf("%d+%di\n",c.real,c.imag);
else
printf("%d%di\n",c.real,c.imag);
}
#program_by : @PLAUnit61398

BY C Language πŸ‘¨β€πŸ’»


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/C_Codings/203

View MORE
Open in Telegram


C Language ‍ Telegram | DID YOU KNOW?

Date: |

Traders also expressed uncertainty about the situation with China Evergrande, as the indebted property company has not provided clarification about a key interest payment.In economic news, the Commerce Department reported an unexpected increase in U.S. new home sales in August.Crude oil prices climbed Friday and front-month WTI oil futures contracts saw gains for a fifth straight week amid tighter supplies. West Texas Intermediate Crude oil futures for November rose $0.68 or 0.9 percent at 73.98 a barrel. WTI Crude futures gained 2.8 percent for the week.

The seemingly negative pandemic effects and resource/product shortages are encouraging and allowing organizations to innovate and change.The news of cash-rich organizations getting ready for the post-Covid growth economy is a sign of more than capital spending plans. Cash provides a cushion for risk-taking and a tool for growth.

C Language ‍ from us


Telegram C Language πŸ‘¨β€πŸ’»
FROM USA