Pages

Wednesday, March 26, 2014

C Program to add two complex numbers

/*example of passing structure to function*/
#include<stdio.h>
#include<stdlib.h>
struct complex
{
       float real, image;
};
complex add(complex,complex);
int main()
{
    struct complex c1,c2,c3;
    printf("enter first complex number: ");
    scanf("%f%f",&c1.real,&c1.image);
    printf("enter second complex number: ");
    scanf("%f%f",&c2.real,&c2.image);
    c3=add(c1,c2);
    printf("\n sum of two complex number:%f+i%f",c3.real,c3.image);
    system ("pause");
    return 0;
}
complex add (complex c1,complex c2)
{
        struct complex c3;
        c3.real=c1.real+c2.real;
        c3.image=c1.image+c2.image;
        return c3;
}

No comments:

Post a Comment