SlideShare a Scribd company logo
/* Write a C program that uses functions to perform the following operations:

           i) Reading a complex number

           ii) Writing a complex number

           iii) Addition of two complex numbers

           iv) Multiplication of two complex numbers

(Note: represent complex number using a structure.) */



#include<stdio.h>

#include<math.h>



void arithmetic(int opern);



struct comp

{

     double realpart;

     double imgpart;

};



void main()

{

     int opern;

     clrscr();

     printf("nn ttt***** MAIN MENU *****");

   printf("nn Select your option: n 1 : ADDn 2 : MULTIPLYn 0 : EXIT nntt Enter your Option
[ ]bb");
scanf("%d",&opern);



    switch(opern)

    {

          case 0:

              exit(0);

          case 1:

          case 2:

              arithmetic(opern);

          default:

              main();

    }



}



void arithmetic(int opern)

{



    struct comp w1, w2, w;



    printf("n Enter two Complex Numbers (x+iy):n Real Part of First Number:");

    scanf("%lf",&w1.realpart);

    printf("n Imaginary Part of First Number:");
scanf("%lf",&w1.imgpart);

printf("n Real Part of Second Number:");

scanf("%lf",&w2.realpart);

printf("n Imaginary Part of Second Number:");

scanf("%lf",&w2.imgpart);




switch(opern)

{



/*addition of complex number*/

case 1:

      w.realpart = w1.realpart+w2.realpart;

      w.imgpart = w1.imgpart+w2.imgpart;

      break;



/*multiplication of complex number*/

case 2:

      w.realpart=(w1.realpart*w2.realpart)-(w1.imgpart*w2.imgpart);

      w.imgpart=(w1.realpart*w2.imgpart)+(w1.imgpart*w2.realpart);

      break;

}
if (w.imgpart>0)

           printf("n Answer = %lf+%lfi",w.realpart,w.imgpart);

    else

           printf("n Answer = %lf%lfi",w.realpart,w.imgpart);

    getch();

    main();

}

More Related Content

PDF
Bcsl 033 data and file structures lab s1-1
DOCX
New microsoft office word document
PDF
Bcsl 033 data and file structures lab s5-3
Bcsl 033 data and file structures lab s1-1
New microsoft office word document
Bcsl 033 data and file structures lab s5-3

What's hot (20)

PDF
Bcsl 033 data and file structures lab s2-2
DOC
Add digits of number in c
DOC
Palindrome number program c
PPTX
Double linked list
DOCX
Pratik Bakane C++
DOC
Shan
DOCX
New microsoft office word document (2)
PDF
Recursion concepts by Divya
DOC
C program to check leap year
PDF
Stack concepts by Divya
PDF
Bcsl 033 data and file structures lab s1-4
DOCX
One dimensional operation of Array in C- language
PPT
StackArray stack3
DOCX
Pratik Bakane C++
DOC
Final ds record
PPTX
C Programming Language Part 4
PPTX
งานนำเสนอ อาจารย์ลาวัลย์
Bcsl 033 data and file structures lab s2-2
Add digits of number in c
Palindrome number program c
Double linked list
Pratik Bakane C++
Shan
New microsoft office word document (2)
Recursion concepts by Divya
C program to check leap year
Stack concepts by Divya
Bcsl 033 data and file structures lab s1-4
One dimensional operation of Array in C- language
StackArray stack3
Pratik Bakane C++
Final ds record
C Programming Language Part 4
งานนำเสนอ อาจารย์ลาวัลย์
Ad

Viewers also liked (12)

Ad

Similar to week-11x (20)

PDF
C lab programs
PDF
C lab programs
DOC
5 Rmi Print
PPTX
Chapter 7 functions (c)
DOC
C important questions
PDF
C programs
PDF
Functions
DOCX
C++ file
DOCX
C++ file
PDF
7 functions
PPTX
C Programming Example
PPTX
ฟังก์ชั่นย่อยและโปรแกรมมาตรฐาน ม. 6 1
PDF
Q1 Consider the below omp_trap1.c implantation, modify the code so t.pdf
PDF
DOCX
Lab6 (pfl) 20_mdele136(ausaf)
PDF
Functions
DOCX
Dam31303 dti2143 lab sheet 7
PDF
PDF
Chapter 5
PPT
lets play with "c"..!!! :):)
C lab programs
C lab programs
5 Rmi Print
Chapter 7 functions (c)
C important questions
C programs
Functions
C++ file
C++ file
7 functions
C Programming Example
ฟังก์ชั่นย่อยและโปรแกรมมาตรฐาน ม. 6 1
Q1 Consider the below omp_trap1.c implantation, modify the code so t.pdf
Lab6 (pfl) 20_mdele136(ausaf)
Functions
Dam31303 dti2143 lab sheet 7
Chapter 5
lets play with "c"..!!! :):)

Recently uploaded (20)

PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PDF
Updated Idioms and Phrasal Verbs in English subject
PPTX
Lesson notes of climatology university.
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PDF
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
LNK 2025 (2).pdf MWEHEHEHEHEHEHEHEHEHEHE
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PPTX
master seminar digital applications in india
PPTX
History, Philosophy and sociology of education (1).pptx
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
UNIT III MENTAL HEALTH NURSING ASSESSMENT
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
Orientation - ARALprogram of Deped to the Parents.pptx
PPTX
Final Presentation General Medicine 03-08-2024.pptx
Microbial disease of the cardiovascular and lymphatic systems
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
Updated Idioms and Phrasal Verbs in English subject
Lesson notes of climatology university.
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
Microbial diseases, their pathogenesis and prophylaxis
LNK 2025 (2).pdf MWEHEHEHEHEHEHEHEHEHEHE
Final Presentation General Medicine 03-08-2024.pptx
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
Chinmaya Tiranga quiz Grand Finale.pdf
master seminar digital applications in india
History, Philosophy and sociology of education (1).pptx
Supply Chain Operations Speaking Notes -ICLT Program
UNIT III MENTAL HEALTH NURSING ASSESSMENT
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Orientation - ARALprogram of Deped to the Parents.pptx
Final Presentation General Medicine 03-08-2024.pptx

week-11x

  • 1. /* Write a C program that uses functions to perform the following operations: i) Reading a complex number ii) Writing a complex number iii) Addition of two complex numbers iv) Multiplication of two complex numbers (Note: represent complex number using a structure.) */ #include<stdio.h> #include<math.h> void arithmetic(int opern); struct comp { double realpart; double imgpart; }; void main() { int opern; clrscr(); printf("nn ttt***** MAIN MENU *****"); printf("nn Select your option: n 1 : ADDn 2 : MULTIPLYn 0 : EXIT nntt Enter your Option [ ]bb");
  • 2. scanf("%d",&opern); switch(opern) { case 0: exit(0); case 1: case 2: arithmetic(opern); default: main(); } } void arithmetic(int opern) { struct comp w1, w2, w; printf("n Enter two Complex Numbers (x+iy):n Real Part of First Number:"); scanf("%lf",&w1.realpart); printf("n Imaginary Part of First Number:");
  • 3. scanf("%lf",&w1.imgpart); printf("n Real Part of Second Number:"); scanf("%lf",&w2.realpart); printf("n Imaginary Part of Second Number:"); scanf("%lf",&w2.imgpart); switch(opern) { /*addition of complex number*/ case 1: w.realpart = w1.realpart+w2.realpart; w.imgpart = w1.imgpart+w2.imgpart; break; /*multiplication of complex number*/ case 2: w.realpart=(w1.realpart*w2.realpart)-(w1.imgpart*w2.imgpart); w.imgpart=(w1.realpart*w2.imgpart)+(w1.imgpart*w2.realpart); break; }
  • 4. if (w.imgpart>0) printf("n Answer = %lf+%lfi",w.realpart,w.imgpart); else printf("n Answer = %lf%lfi",w.realpart,w.imgpart); getch(); main(); }