Powered By Blogger

Friday, April 27, 2012

Program : 15


PROGRAM - 15

Write a program that uses the functions to perform the following:
a)  Reading a complex number.
b)  Writing a Complex number.
c)  Addition of two complex numbers.
d)  Multiplication of two Complex numbers.

Program:

#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<stdlib.h>
void arth(int);
struct comp
{
     double rp;
     double ip;
};
void main()
{
     int op;
     clrscr();
     printf("\nMAIN MENU");
     printf("select \n 1. ADDTION\n 2. MULTIPLICATION\n
                                        0. EXIT\n");
     scanf("%d",&op);
     switch(op)
     {
          case 0:exit(0);
          case 1:
          case 2:
          arth(op);
          break;
          default:
          printf("\n invalid statement");
          exit(0);
     }
}
void arth(int op)
{
     struct comp w1,w2,w;
     printf("enter the first complex number:");
     scanf("%lf",&w1.rp);
     scanf("%lf",&w1.ip);
     printf("enter the second complex number:");
     scanf("%lf",&w2.rp);
     scanf("%lf",&w2.ip);
     switch(op)
     {
        case 1:
        w.rp=w1.rp+w2.rp;
        w.ip=w1.ip+w2.ip;
        break;
        case 2:
        w.rp=(w1.rp*w2.rp)-(w1.ip*w2.ip);
        w.ip=(w1.rp*w2.ip)+(w1.ip*w2.rp);
        break;
     }
     if(w.ip>0)
     printf("answer=%lf+i%lf",w.rp,w.ip);
     else
     printf("answer=%lf-i%lf",w.rp,w.ip);
     getch();
}
/*
IPNPUT:MAIN MENUSELECT
 1. ADDTION
 2. MULTIPLICATION
 0. EXIT
your option is:2
enter the first complex number:2     3
enter the second complex number:4    5
answer=-7.000000+i22.000000
MAIN MENUselect
 1. ADDTION
 2. MULTIPLICATION
 0. EXIT
 1
enter the first complex number:3     4
enter the second complex number:5    6
answer=8.000000+i10.000000
*/

No comments:

Post a Comment