Skip to content

Instantly share code, notes, and snippets.

@NeoHBz
Created January 3, 2022 05:56
Show Gist options
  • Save NeoHBz/c98d01e480e347d797c82c1b8926909d to your computer and use it in GitHub Desktop.
Save NeoHBz/c98d01e480e347d797c82c1b8926909d to your computer and use it in GitHub Desktop.
#include <stdio.h>
struct complex
{
float real;
float imaginary;
};
void input(struct complex*);
void display(struct complex);
struct complex product(struct complex, struct complex);
int main()
{
struct complex c1, c2, c3;
printf("\nFor Complex Number 1:");
input(&c1);
printf("\nFor Complex Number 2:");
input(&c2);
printf("\n\nComplex number 1 is ");
display(c1);
printf("\nComplex number 2 is ");
display(c2);
c3 = product(c1, c2);
printf("\nTheir Product = ");
display(c3);
return 0;
}
void input(struct complex *t)
{
printf("\nEnter value of\n");
printf("real part : ");
scanf("%f", &t->real);
printf("imaginary part : ");
scanf("%f", &t->imaginary);
}
void display(struct complex c)
{
printf("\n%0.2f + %0.2f i", c.real, c.imaginary);
}
struct complex product(struct complex t1, struct complex t2)
{
struct complex t;
t.real = t1.real * t2.real - t1.imaginary * t2.imaginary;
t.imaginary = t1.real * t2.imaginary + t1.imaginary * t2.real;
return t;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment