Sei sulla pagina 1di 2

/* ROLL NO: 1 SEM-1 ICA DIV: A

NAME : VARUN AGGARWAL SUBJECT: FOP


PROGRAM DEFINITION: write a function to add,sub,div and
multiply two complex numbers(x+iy)&(a+ib)
*/

#include<stdio.h>
#include<conio.h>

void add(int ,int ,int ,int,FILE *fp);


void sub(int ,int ,int ,int,FILE *fp);
void mul(int ,int ,int ,int,FILE *fp);

int main()
{
int x,y,a,b;
FILE *fp;
clrscr();
fp=fopen("z:\\matrix.txt","w");
printf("Enter the value of x: ");
scanf("%d",&x);
printf("Enter the value of y: ");
scanf("%d",&y);
printf("Enter the value of a: ");
scanf("%d",&a);
printf("Enter the value of b: ");
scanf("%d",&b);
printf("\nComplex number 1");
if(y>0)
printf("\n%d+%di",x,y);
else
printf("\n%d%di",a,b);
printf("\nComplex number 2");
if(b>0)
printf("\n%d+%di",a,b);
else
printf("\n%d%di",a,b);
add(x,y,a,b,fp);
sub(x,y,a,b,fp);
getch();
return 0;
}

void add(int x,int y,int a,int b,FILE *fp)


{
int x_a,y_b;
printf("\nAfter adding\n");
x_a=x+a;
y_b=y+b;
if(y_b>0)
{
printf("%d+%di",x_a,y_b);
fprintf(fp,"%d+%di",x_a,y_b);
}
else
{
printf("%d%di",x_a,y_b);
fprintf(fp,"%d+%di",x_a,y_b);
}
}

void sub(int x,int y,int a,int b,FILE *fp)


{
int x_a,y_b;
printf("\nAfter subtracting\n");
x_a=x-a;
y_b=y-b;
if(y_b>0)
{
printf("%d+%di",x_a,y_b);
fprintf(fp,"%d+%di",x_a,y_b);
}
else
{
printf("%d%di",x_a,y_b);
fprintf(fp,"%d%di",x_a,y_b);
}
}
void mul(int x,int y,int a,int b,FILE *fp)
{
int x_a,y_b;
printf("\nAfter adding\n");
x_a=x+a;
y_b=y+b;
if(y_b>0)
{
printf("%d+%di",x_a,y_b);
fprintf(fp,"%d+%di",x_a,y_b);
}

else

{
printf("%d%di",x_a,y_b);
fprintf(fp,"%d+%di",x_a,y_b);
}

}
/* output:

Enter the value of x: 2


Enter the value of y: 3
Enter the value of a: 4
Enter the value of b: 4

Complex number 1
2+3i
Complex number 2
4+4i
After adding
6+7i
After subtracting
-2-1i
*/

Potrebbero piacerti anche