Saturday 18 December 2010

Algorithm for To read the two complex numbers and perform the addition and multiplication of these two numbers

Description:


In this program the complex number means it contains the two parts . first one
is real part and second one is imaginary part(2+3i).by taking these two complex numbers we can perform the addition and multiplication operation.

Algorithm:



Step 1: Start
Step 2: declare structure for complex numbers
Step 3: read the complex number

Step 4: read choice
Step 5: if choice=1 then addition operation will perform and it contains following steps

i)    w.realpart = w1.realpart+w2.realpart;
ii)  w.imgpart = w1.imgpart+w2.imgpart;
 goto step 4

Step 6: if choice=2 then multiplication operation will perform and it contains following steps

i)    w.realpart=(w1.realpart*w2.realpart)-(w1.imgpart*w2.imgpart);
ii)                                  w.imgpart=(w1.realpart*w2.imgpart)+(w1.imgpart*w2.realpart);
goto step 4

Step 7: if choice=0 then exit operation will perform


Step 8:if w.imgpart>0 then print realpart+imgpart else
Print realpart.
Step 9: Stop


Output:

***** MAIN MENU *****

Select your option:
1 : ADD
2 : MULTIPLY
0 : EXIT

Enter your Option [ 1]

Enter two Complex Numbers (x+iy):
Real Part of First Number:2
Imaginary Part of First Number:2

Real Part of Second Number:2
Imaginary Part of Second Number:2

Answer = 4.000000+4.000000i
***** MAIN MENU *****
Select your option:
1 : ADD
2 : MULTIPLY
0 : EXIT

Enter your Option [ 2]

Enter two Complex Numbers (x+iy):
Real Part of First Number:2
Imaginary Part of First Number:2

Real Part of Second Number:2
Imaginary Part of Second Number:2

Answer = 0.000000+8.000000i

***** MAIN MENU *****

Select your option:
1 : ADD
2 : MULTIPLY
0 : EXIT

Enter your Option  3
invalid option

***** MAIN MENU *****

Select your option:
 1 : ADD
2 : MULTIPLY
0 : EXIT

Enter your Option [ 0]

Conclusion: The program is error free

VIVA QUESTIONS:

1) Define structure ?
Ans: Structure is amethod for packing data of different types. Structure help to organize complex data in a more meaninigful way.

2) What is use of <math.h> header file ?
Ans: It is used to access the mathematical functions in programs.




program

No comments:

Post a Comment