Back To C++ Structures
nested structure means structure within a structure
//program to create a structure complex number with members(real and imaginary), creates two structure variables and passes these variables to function which calculates sum of two complex number structure variables #include
#include
struct complex { int real; int imaginary; }; void sum(complex a,complex b) { complex c; c.real=a.real+b.real; c.imaginary=a.imaginary+b.imaginary; cout<<"\ndisplaying sum of two complex numbers"; cout<<"\nreal part is "<
>a.real; cout<<"\nenter imaginary part of complex number a "; cin>>a.imaginary; cout<<"\nenter data for complex number b "; cout<<"\nenter real part of complex number b "; cin>>b.real; cout<<"\nenter imaginary part of complex number b "; cin>>b.imaginary; cout<<"\ncomputing the sum of complex numbers a and b\n"; sum(a,b); getch(); }