## Program to add and subtract two complex numbers using structures.

```#include<stdio.h>
#include<conio.h>
struct hi
{
int real1,real2;
int comp1,comp2;
} arith;
main()
{
int a;
printf("Enter the real and imaginary part of first number respectively\n");
scanf("%d",&arith.real1);
scanf("%d",&arith.comp1);
printf("Enter the real and imaginary part of second number respectively\n");
scanf("%d",&arith.real2);
scanf("%d",&arith.comp2);
scanf("%d",&a);
if(a==1)
{
}
else if(a==2)
{
printf("Subtraction - %d + (%di)",arith.real1-arith.real2,arith.comp1-arith.comp2);
}
else
{
printf("Not a valid operation.");

}

}```

Output:

## Program to read display add and subtract the two distances using structures

```#include<stdio.h>
#include<conio.h>
struct hi
{
int k1,k2;
int m1,m2;
} kil;
main()
{
int a;
printf("Enter the first distance in parts of kilometres and metres respectively\n");
scanf("%d",&kil.k1);
scanf("%d",&kil.m1);
printf("Enter the second distance in parts of kilometres and metres respectively\n");
scanf("%d",&kil.k2);
scanf("%d",&kil.m2);
scanf("%d",&a);
if(a==1)
{
printf("Addition - %d Kilometres & %d Metres",kil.k1+kil.k2,kil.m1+kil.m2);
}
else if(a==2)
{
printf("Subtraction - %d Kilometres & %d Metres)",kil.k1-kil.k2,kil.m1-kil.m2);
}
else if(a==3)
{
printf("Distances entered by you:\n1. %d Kilometres & %d Metres",kil.k1,kil.m1);
printf("Distances entered by you:\n2. %d Kilometres & %d Metres",kil.k2,kil.m2);
}

else if(a==4)
{
printf("Distances entered by you:\n1. %d Kilometres & %d Metres",kil.k1,kil.m1);
printf("Distances entered by you:\n2. %d Kilometres & %d Metres",kil.k2,kil.m2);
}
else if(a==5)
{
exit(1);
}

else
{
printf("Not a valid operation.");

}

}```

Output: