Complex number addition using structures in C


#include <stdio.h
> typedef struct complex{ float imag; float real; } comp; void addc(comp c1,comp c2){ float real = c1.real + c2.real; float imag = c1.imag + c2.imag; printf("%.2f + %.2fi",real,imag); printf("\n"); } int main(){ comp c1,c2; printf("Enter first complex number: "); scanf("%f+%fi",&c1.real,&c1.imag); printf("Enter second complex number: "); scanf("%f+%fi",&c2.real,&c2.imag); // c1.imag=3; // c1.real=4; // c2.real=8; // c2.imag=5; printf("Addition result is "); addc(c1,c2); return 0; } //Program by : TEJAS
Output

Comments

Popular Posts