我需要編寫一個程序,它使用結構來定義複數,即z1 = x + yi。然後添加2個複數。在繼續使用我的代碼之前,我需要弄清楚如何正確初始化它們。到目前爲止,我已經嘗試了一些東西,這是我已經提出的最好的,它仍然沒有編譯。結構如何用來表示複數
這裏是我的代碼的副本,我只需要修復這部分,然後我就可以自己完成其餘的工作。
#include<stdio.h>
typedef struct complex1{
float *real1;
float *imaginary1;
} complex1;
typedef struct complex2{
float *real2;
float *imaginary2;
} complex2;
int main(){
struct complex1 real;
struct complex1 *realptr;
struct complex1 imaginary;
struct complex1 *imaginaryptr;
struct complex2 real;
struct complex2 *realptr;
struct complex2 imaginary;
struct complex2 *imaginaryptr;
printf("Please enter variable x1.");
scanf("%d", &real.real1);
printf("Please enter variable y1.");
scanf("%d", &imaginary.imaginary1);
printf("Please enter variable x2.");
scanf("%d", &real.real2);
printf("Please enter variable y2.");
scanf("%d", &imaginary.imaginary2);
printf("You have entered: %d,%d,%d,%d\n",
real.real1, imaginary.imaginary1,real.real2, imaginary.imagnary2);
return 0;
}
什麼是編譯錯誤消息? – 2011-02-23 16:16:36
'真實'重新定義基本類型。 – none 2011-02-23 16:18:16
它也表示,對於我在主函數 – none 2011-02-23 16:18:58