WACP To Add Two Complex Numbers Using Structure

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

//WACP to add two complex numbers using structure

#include <stdio.h>

struct complex

int real, img;

};

int main()

struct complex a, b, c;

printf("Enter a and b where a + ib is the first complex number.\n");

scanf("%d%d", &a.real, &a.img);

printf("Enter c and d where c + id is the second complex number.\n");

scanf("%d%d", &b.real, &b.img);

c.real = a.real + b.real;

c.img = a.img + b.img;

printf("Sum of the complex numbers: (%d) + (%di)\n", c.real, c.img);


return 0;}

//WACP to enter details of book using structure and display them

#include<stdio.h>

struct book

char author[30];

char title[20];

float price;

};

struct book input()

struct book b2;

printf("enter book author\n");

gets(b2.author);

fflush(stdin);

printf("enter title\n ");

gets(b2.title);

printf("enter price\n");

scanf("%f",&b2.price);

return(b2);
}

void display(struct book b)

printf("author is : %s\n",b.author);

printf("title is : %s\n",b.title);

printf("price is : %f\n",b.price);

void main()

struct book b1;

b1=input();

display(b1);

You might also like