write a program to add, subtract, multiply and divide complex numbers
#include <stdio.h>
#include <conio.h>
main()
{
int x, y, a, b, ar, ai, sr, si, mr, mi, dr, di, q;
clrscr();
printf(“\nEnter four numbers”); scanf(“%d%d%%d%d”, &x, &y, &a, &b);
ar = x + a;
ai = y + b;
SI = x – a;
mr = (x * a) – (y * b);
mi = (x * b) + (y * a);
dr = (x * a) + (y * b);
di = -(x * b) + (y * a);
q = (a * a) + (b * b);
printf(“\nSum is %d + i (%d)”, ar, ai);
printf(“\nDifference is %d + i (%d)”, sr, si);
printf(“\nProduct is %d + i (%d)”, mr, mi);
printf(“\nQuotient is %f + i(f)”, dr*1.0/q, di*1.0/q);
}
Shell Script 2.18:
#Script to add, subtract, multiply and divide two complex numbers.
echo “Enter four numbers”
read x y a b
ar= expr $x + $a`
ai-‘expr Sy + $b`
sr= expr $x – $a`
si= expr $y – $b`
mr= expr $x \* $a – Sy \* $b` mi= expr $x \* $b + $y \* $a` dr-expr $x \* $a + $y \* $b`
di= echo -$x \* $b + $y \* $a | bc` q- echo $a \* $a + $b \* $b | bc` qq1=`echo $dr \* 1.0 / $q | bc` 992- echo $di \* 1.0 / $q | bc`
echo “Sum is
echo “Difference is echo “Product is. echo “Quotient is
$ar + i \($ai\)”
$sri \($si\)” $mri \($mi\)” $qq1+ i \($qq2\)”