c - How can structures be used to represent complex numbers -
i need write program uses structures define complex numbers ie z1 = x + yi. , adds 2 complex numbers. need figure out how initalise them before moving on code. i've tried few things far, best have come , it's still not compiling.
here's copy of code, need fix part , able rest myself.
#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; } 
there multiple errors in file, maybe more want ?
#include<stdio.h>  typedef struct _complex1{     double real1;     double imaginary1; } complex1; do not name struct twice same name, , believe want skip pointers real1 , imaginary1 -- since not gain anything.
int main(){   complex1 real;   complex1 *realptr;   complex1 imaginary;   complex1 *imaginaryptr;   complex2 real2;   complex2 *realptr2;   complex2 imaginary2;   complex2 *imaginaryptr2; the complex typedefs tell compiler struct. , can not have 2 variables same name.
  printf("please enter variable x1.");   scanf("%lf", &real.real1); you need align sending scanf expects. %f expects double * , not double ** or (float ** in case).
Comments
Post a Comment