New Member FAQ | Forums | Earn Revenue


Resources Entrance Ask Experts Exam Papers Jobs English Projects Universities Colleges Courses Schools Training My India



My Profile
Active Members
TodayLast 7 Days more...



Awards & Gifts
Online Exams

Fresher Jobs


Our fresher job section is exclusively for fresh graduates! Find jobs for freshers in major Indian cities including Bangalore, Chennai, Hyderabad, Pune or Kochi

Resources


Find educational articles, blogs, discussion threads and other resources.

Colleges


Find details about any college in India or search for courses.

website counter



Complex Numbers Arithmetic in C


Posted Date:     Total Responses: 0    Posted By: Vikram Narayan C   Member Level: Silver   Points/Cash: 5   


#include //stdio.h
#include //conio.h
#include //math.h
#include //graphics.h

struct complex1
{
float a;
float b;
}cmp[10],csum,cdiff,cpro,cdiv;

int i=0;
float mod;

void init()
{
for(i=0;i<10;i++)
{
cmp[i].a=0;
cmp[i].b=0;
}
csum.a=0;csum.b=0;
cdiff.a=0;cdiff.b=0;
cpro.a=0;cpro.b=0;
}

void c_sum(int n)
{
for(i=0;i {
csum.a=csum.a+cmp[i].a;
csum.b=csum.b+cmp[i].b;
}
}

void c_sub()
{
cdiff.a=cmp[0].a-cmp[1].a;
cdiff.b=cmp[0].b-cmp[1].b;
}

void c_mul()
{
cpro.a=cmp[0].a*cmp[1].a-cmp[0].b*cmp[1].b;
cpro.b=cmp[0].b*cmp[1].a+cmp[0].a*cmp[1].b;
}

void c_mod()
{
mod=sqrt(pow(cmp[0].a,2)+pow(cmp[0].b,2));
}

void c_conj(struct complex1 *temp)
{
temp->a=temp->a;
temp->b=-temp->b;
}

void c_div()
{
struct complex1 t=cmp[0],q=cmp[0],d=cmp[1];
c_conj(&cmp[1]);
c_mul();
q=cpro;
cmp[0]=d;
c_mul();
cdiv.a=q.a/cpro.a;
cdiv.b=q.b/cpro.a;
cmp[0]=t;
cmp[1]=d;
}

void c_input(int n)
{
for(i=0;i {
printf("\nEnter the complex no. %d: ",i+1);
scanf("%f %f",&cmp[i].a,&cmp[i].b);
}
}

void c_print(int n)
{
printf("\nThe Complex Numbers are:\n");
for(i=0;i printf("\nComplex No.%d : %.2f+ i%.2f",i+1,cmp[i].a,cmp[i].b);
}

void complex()
{
int ch,n;
int ch1,ch2,j,np;
int gd=DETECT,gm,x,y;
init();
gotoxy(30,5);
printf("COMPLEX NUMBERS");
printf("\n1.Addition...");
printf("\n2.Subtraction...");
printf("\n3.Multiplication...");
printf("\n4.Modulus...");
printf("\n5.Division...");
printf("\n6.Conjugate...");
printf("\n7.2d Representation...");
printf("\n8.Exit...");
printf("\n\tEnter your choice:");
scanf("%d",&ch);
clrscr();

switch(ch)
{
case 1: printf("\nWELCOME TO ADDITION...");
init();
printf("\nEnter the number of complex numbers to add:");
scanf("%d",&n);
c_input(n);
clrscr();
c_print(n);
c_sum(n);
printf("\n\nThe Sum of the Complex Numbers: %.2f + i %.2f",csum.a,csum.b);
break;
case 2: printf("\nWELCOME TO SUBRACTION...");
init();
clrscr();
c_input(2);
c_print(2);
c_sub();
printf("\n\nThe Difference of the Complex Numbers: %.2f + i %.2f",cdiff.a,cdiff.b);
break;
case 3: printf("\nWELCOME TO MULTIPLICATION...");
init();
c_input(2);
clrscr();
c_print(2);
c_mul();
printf("\n\nThe Product of the Complex numbers: %.2f + i %.2f",cpro.a,cpro.b);
break;
case 4: printf("\nWELCOME TO MODULUS...:");
init();
c_input(1);
c_mod();
clrscr();
c_print(1);
printf("\nThe modulus is : %.2f",mod);
break;
case 5: printf("\nWELCOME TO DIVISION");
init();
c_input(2);
c_div();
clrscr();
c_print(2);
printf("\nThe Output is : %.2f + i%.2f",cdiv.a,cdiv.b);
break;
case 6: printf("\nWELCOME TO CONJUGATE");
init();
c_input(1);;
c_conj(&cmp[0]);
c_print(1);
break;
case 7: printf("\nWELCOME TO 2D REPRESENTATION:");
init();
printf("\n1.Point...");
printf("\n2.Line...");
printf("\n3.Rotation...");
printf("\nEnter your choice:");
scanf("%d",&ch1);
switch(ch1)
{
case 1:
c_input(1);
initgraph(&gd,&gm,"f:\\vikram\\compiler\\tc\\bgi");
x=getmaxx();
y=getmaxy();
setbkcolor(9);
line(x/2,0,x/2,y);
line(0,y/2,x,y/2);
outtextxy(x-20,y/2-10,"X");
outtextxy(x/2+10,10,"Y");
outtextxy(x/2-10,y/2+10,"O");
circle(x/2+20*cmp[0].a,y/2-20*cmp[0].b,2);
setcolor(GREEN);
line(x/2+20*cmp[0].a,y/2-20*cmp[0].b,x/2,y/2);
outtextxy(x/2+20*cmp[0].a+5,y/2-20*cmp[0].b+5,"Z");
getch();
break;
case 2: printf("\nEnter number of points:");
scanf("%d",&np);
c_input(np);
initgraph(&gd,&gm,"f:\\vikram\\compiler\\tc\\bgi\\");
x=getmaxx();
y=getmaxy();
setbkcolor(9);
line(x/2,0,x/2,y);
line(0,y/2,x,y/2);
outtextxy(x-20,y/2-10,"X");
outtextxy(x/2+10,10,"Y");
outtextxy(x/2-10,y/2+10,"O");
for(j=0;j circle(x/2+20*cmp[j].a,y/2-20*cmp[j].b,2);
for(j=0;j line(x/2+20*cmp[j].a,y/2-20*cmp[j].b,x/2+20*cmp[j+1].a,y/2-20*cmp[j+1].b);
getch();
break;
case 3: c_input(1);
printf("\n1.90 degree AntiClockwise...");
printf("\n2.90 degree Clockwise...\n");
scanf("%d",&ch2);
initgraph(&gd,&gm,"f:\\vikram\\compiler\\tc\\bgi");
x=getmaxx();
y=getmaxy();
setbkcolor(9);
line(x/2,0,x/2,y);
line(0,y/2,x,y/2);
outtextxy(x-20,y/2-10,"X");
outtextxy(x/2+10,10,"Y");
outtextxy(x/2-10,y/2+10,"O");
circle(x/2+20*cmp[0].a,y/2-20*cmp[0].b,2);
setcolor(GREEN);
line(x/2+20*cmp[0].a,y/2-20*cmp[0].b,x/2,y/2);
switch (ch2)
{
case 1: cmp[1].a=0;
cmp[1].b=1;
c_mul();
break;
case 2: cmp[1].a=0;
cmp[1].b=-1;
c_mul();
break;
}
setcolor(WHITE);
circle(x/2+20*cpro.a,y/2-20*cpro.b,2);
line(x/2+20*cpro.a,y/2-20*cpro.b,x/2,y/2);
getch();
break;
}
break;
}

getch();
}


Project Feedbacks


No feedbacks found. Be the first to respond and make money from revenue sharing program.

Post Feedback
You must Sign In to post a feedback.
Next Project: Basic Matrix Functions in C
Previous Project: project to calculate area using c++

Return to Project Index

Post New Project


Related Projects



Advertise Here





Contact Us   Advertise   Editors    Privacy Policy    Terms Of Use   

ISC Technologies.
2006 - 2009 All Rights Reserved.