100% found this document useful (1 vote)
54 views

WACP To Add Two Complex Numbers Using Structure

The document contains code to add two complex numbers using a structure with real and imaginary number fields. It also contains code to define a book structure with author, title, and price fields, accept user input for a book object, and display the fields of a book object.

Uploaded by

flying ostrich
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
54 views

WACP To Add Two Complex Numbers Using Structure

The document contains code to add two complex numbers using a structure with real and imaginary number fields. It also contains code to define a book structure with author, title, and price fields, accept user input for a book object, and display the fields of a book object.

Uploaded by

flying ostrich
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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