C Programming Code Examples C > Functions Code Examples C Program to Add Two Complex Numbers by Passing Structure to a Function C Program to Add Two Complex Numbers by Passing Structure to a Function In this program, structures j1 and j2 are passed as an argument of function add(). This function computes the sum and returns the structure variable temp to the main() function. #include <stdio.h> typedef struct complex { float real; float imag; } complex; complex add(complex j1,complex j2); int main() { complex j1, j2, temp; printf("For 1st complex number \n"); printf("Enter real and imaginary part respectively:\n"); scanf("%f %f", &j1.real, &j1.imag); printf("\nFor 2nd complex number \n"); printf("Enter real and imaginary part respectively:\n"); scanf("%f %f", &j2.real, &j2.imag); temp = add(j1, j2); printf("Sum = %.1f + %.1fi", temp.real, temp.imag); return 0; } complex add(complex j1, complex j2) { complex temp; temp.real = j1.real + j2.real; temp.imag = j1.imag + j2.imag; return(temp); }