C 利用结构进行复数加法

C 利用结构进行复数加法,c,struct,dev-c++,complex-numbers,C,Struct,Dev C++,Complex Numbers,为什么此代码在Dev CPP上完美执行,但在Borland Turbo C上无法执行 在Turbo C中执行时,它显示输入实部:堆栈溢出 #include<stdio.h> #include<conio.h> #include<stdlib.h> struct complex { int real; int img; }; typedef struct complex com; com read(com); com add(com,com); void

为什么此代码在
Dev CPP
上完美执行,但在
Borland Turbo C
上无法执行

在Turbo C中执行时,它显示
输入实部:堆栈溢出

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

struct complex
{
 int real;
 int img;
};

typedef struct complex com;
com read(com);
com add(com,com);
void show(com);

void main()
{
 com c1,c2,c3;
 clrscr();
 c1=read(c1);
 c2=read(c2);
 c3=add(c1,c2);
 show(c3);
 getch();
}

com read(com c)
{
 printf("Input real part: ");
 scanf("%d",&c.real);
 printf("Input imaginary part: ");
 scanf("%d",&c.img);
 return (c);
}

void show(com c)
{
 printf("%d+%di",c.real,c.img);
}

com add(com c1,com c2)
{
 com c3;
 c3.img=c1.img+c2.img;
 c3.real=c1.real+c2.real;
 return (c3);
}
#包括
#包括
#包括
结构复合体
{
int-real;
int img;
};
typedef-struct-complex-com;
com读取(com);
com添加(com,com);
空展(com),;
void main()
{
com c1、c2、c3;
clrsc();
c1=读取(c1);
c2=读取(c2);
c3=添加(c1,c2);
show(c3);
getch();
}
com读取(com c)
{
printf(“输入实部:”);
scanf(“%d”和c.real);
printf(“输入虚部:”);
scanf(“%d”和c.img);
返回(c);
}
无效显示(com c)
{
printf(“%d+%di”,c.real,c.img);
}
通信添加(通信c1、通信c2)
{
com c3;
c3.img=c1.img+c2.img;
c3.实数=c1.实数+c2.实数;
返回(c3);
}

无需按值传递结构成员。 可以执行以下操作:

#include<stdio.h>
#include<stdlib.h>

struct complex
{
  int real;
  int img;
};

typedef struct complex com;
void read(com *);
void add(com,com, com *);
void show(com);

int main()
{
  com c1,c2,c3;
  read(&c1);
  read(&c2);
  add(c1,c2, &c3);
  show(c3);
  return 0;
}

void read(com *c)
{
  printf("Input real part: ");
  scanf("%d",&c->real);
  printf("Input imaginary part: ");
  scanf("%d",&c->img);
}

void show(com c)
{
  printf("%d+%di",c.real,c.img);
}

void add(com c1,com c2, com *c3)
{
  c3->img=c1.img+c2.img;
  c3->real=c1.real+c2.real;
}
#包括
#包括
结构复合体
{
int-real;
int img;
};
typedef-struct-complex-com;
无效读取(com*);
无效添加(com、com、com*);
空展(com),;
int main()
{
com c1、c2、c3;
read(&c1);
读取(&c2);
添加(c1、c2和c3);
show(c3);
返回0;
}
无效读取(com*c)
{
printf(“输入实部:”);
scanf(“%d”,&c->real);
printf(“输入虚部:”);
scanf(“%d”和&c->img);
}
无效显示(com c)
{
printf(“%d+%di”,c.real,c.img);
}
无效添加(com c1、com c2、com*c3)
{
c3->img=c1.img+c2.img;
c3->real=c1.real+c2.real;
}

无需按值传递结构成员。 可以执行以下操作:

#include<stdio.h>
#include<stdlib.h>

struct complex
{
  int real;
  int img;
};

typedef struct complex com;
void read(com *);
void add(com,com, com *);
void show(com);

int main()
{
  com c1,c2,c3;
  read(&c1);
  read(&c2);
  add(c1,c2, &c3);
  show(c3);
  return 0;
}

void read(com *c)
{
  printf("Input real part: ");
  scanf("%d",&c->real);
  printf("Input imaginary part: ");
  scanf("%d",&c->img);
}

void show(com c)
{
  printf("%d+%di",c.real,c.img);
}

void add(com c1,com c2, com *c3)
{
  c3->img=c1.img+c2.img;
  c3->real=c1.real+c2.real;
}
#包括
#包括
结构复合体
{
int-real;
int img;
};
typedef-struct-complex-com;
无效读取(com*);
无效添加(com、com、com*);
空展(com),;
int main()
{
com c1、c2、c3;
read(&c1);
读取(&c2);
添加(c1、c2和c3);
show(c3);
返回0;
}
无效读取(com*c)
{
printf(“输入实部:”);
scanf(“%d”,&c->real);
printf(“输入虚部:”);
scanf(“%d”和&c->img);
}
无效显示(com c)
{
printf(“%d+%di”,c.real,c.img);
}
无效添加(com c1、com c2、com*c3)
{
c3->img=c1.img+c2.img;
c3->real=c1.real+c2.real;
}

Turbo C-一个非常好的编译器。。。1987年。帮自己一个忙-释放一些磁盘空间。+1以上的评论。Turbo C-一个非常好的编译器。。。1987年。帮你自己一个忙-释放一些磁盘空间。+1以上的评论。