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

Week- 8 STRUCTURES

NAME: SALMAN AHMED QUADRI


ROLLNO: 16951A2172
YEAR: I
SEMESTER: II
COURSE NAME: C PROGRAMING LAB
COURSE CODE: ACS101
PROGRAM: TO PERFORM THE ADDITION, SUBSTRACTION, MULTIPLICATION AND DIVISON
OPERATIONS BETWEEN COMPLEX NUMBERS

ALGORITHM:
1. Start

2. Declare structure for complex numbers

3. Read the complex number

4. Read choice

5. Iif choice = 1 then addition operation will perform and it contains following steps

5.1. w.realpart = w1.realpart + w2.realpart;

5.2. w.imgpart = w1.imgpart + w2.imgpart; goto step 4

6. if choice = 2 then multiplication operation will perform and it contains following steps

6.1. w.realpart = (w1.realpart * w2.realpart)-(w1.imgpart * w2.imgpart);

6.2. w.imgpart = (w1.realpart * w2.imgpart)+(w1.imgpart * w2.realpart); goto step 4

7. if choice = 0 then exit operation will perform

8. if w.imgpart> 0 then print realpart+imgpart else Print realpart.

9. Stop

PROGRAM
#include<stdio.h>

#include<conio.h>

struct complex

{
int real;

int imaginary;

}c1,c2;

void read();

void display();

void add(struct complex,struct complex);

void sub(struct complex,struct complex);

void mul(struct complex,struct complex);

void main()

read();

display();

add(c1,c2);

sub(c1,c2);

mul(c1,c2);

void read()

printf("enter the first complex number");

scanf("%d%d",&c1.real,&c1.imaginary);

printf("\nenter the second complex number");

scanf("%d %d",&c2.real,&c2.imaginary);

void display()

printf("the first complex number is");

printf("\n c1=%d+i%d",c1.real,c2.imaginary);
printf("the second complex number is");

printf("\n c2=%d+i%d",c2.real,c2.imaginary);

void add(struct complex a,struct complex b)

struct complex c3;

c3.real=a.real+b.real;

c3.imaginary=a.imaginary+b.imaginary;

printf("\n the addition of two complex numbers is c3=%d+i%d",c3.real,c3.imaginary);

void sub(struct complex a,struct complex b)

struct complex c4;

c4.real=a.real-b.real;

c4.imaginary=a.imaginary-b.imaginary;

printf("\n the addition of two complex numbers is c4=%d-i%d",c4.real,c4.imaginary);

void mul(struct complex a,struct complex b)

struct complex c5;

c5.real=((a.real*b.real)-(a.imaginary*b.imaginary));

c5.imaginary=((a.imaginary*b.real)+(a.real*b.imaginary));

printf("\n the product of the two complex numbers is %d+i%d",c5.real,c5.imaginary);

INPUT : Enter the first complex number 1 3

Enter the second complex number 4 5


OUTPUT : The first complex number is c1=1+i3

The second complex number is c2=4+i5

The addition of the two complex numbers is


c3=5+i8

The subtraction of the two complex numbers is


c4=- 3+i(-2)

The product of the two complex numbers is

c5=-11+i17

PROGRAM: TO DISPLAY THE NAME AND GROSS SALARY OF


FIVE EMPLOYEES
ALGORITHM:
Print the employees name and gross salary
1. Start
2. Declare structure for employee details

3. Read 100 employee details

4. Repeat loop 100 employees and calculate gross salary of each employee

5. Print each employee name and gross salary

6. Stop

PROGRAM
#include<stdio.h>

struct employee

char name[20];

float basic;

float da;

float gross;

}e[5];

void main()

inti;

for(i=0;i<5;i++)

scanf("%s%f",e[i].name,&e[i].basic);

for(i=0;i<5;i++)

e[i].da=52.0/100*e[i].basic;

e[i].gross=e[i].da+e[i].basic;

printf("\n name=%s gross=%f",e[i].name,e[i].gross);

INPUT : Akash 100000.0


Navneeth 2000000

Blessington 100.0

Ranjith 1.0

Sanpar 50.0

OUTPUT : Name = Akash Gross = 152000.00

Name = Navneeth Gross = 30400.00

Name = Blessington Gross = 152.00

Name = Ranjith Gross = 1.5200

Name = Sanpar Gross = 76.00

PROGRAM: TO PASS A STRUCTURE AS A FUNCTION ARGUMENT


AND PRINT THE BOOK DETAILS
ALGORITHM:
1. Start

2. Declare structure for book details

3. Assign a book details to structure

4. Pass a structure as argument in function

5. Print the book details from the function

6. stop

PROGRAM:
#include <stdio.h>

#include <string.h>

#include<conio.h>

struct Books

char title[50];

char author[50];

char subject[100];

intbook_id;

};

void printBook( struct Books book );

void main( ) {

struct Books Book1;

struct Books Book2;

strcpy( Book1.title, "Nenunaapaithyam");

strcpy( Book1.author, "Pawankalyan");

strcpy( Book1.subject, "Gabbarsingh");

Book1.book_id = 6495407;

strcpy( Book2.title, "Bahubali the begining");


strcpy( Book2.author, "Rajamouli");

strcpy( Book2.subject, "Bahubali series");

Book2.book_id = 6495700;

printf("The details of the book 1 are\n");

printBook(Book1);

printf("The details of the book 2 are\n");

printBook(Book2);

getch();

void printBook( struct Books book )

printf("Book title : %s\n", book.title);

printf("Book author : %s\n", book.author);

printf("Book subject : %s\n", book.subject);

printf("Book book_id : %d\n", book.book_id);

INPUT : Nenunaapaithyam

Pawankalyan

Gabbarsingh

Bahubali the beginning

Rajamouli

Bahubali series

OUTPUT :The details of book 1 are

Book title : Nenunaapaithyam


Book author : Pawankalyan

Book subject : Gabbarsingh

Book_id : 649507

The details of the book 2 are

Book title : Bahubali the begining

Book author : Rajamouli

Book subject : Bahubali series

Book_id : 6495700

PROGRAM: TO DISPLAY YOUR PRESENT ADDRESS USING UNION


ALGORITHM:
To display your present address using union
1. Start

2. Declare union for address details

3. Assign address to union

4. Print union details


5. Stop

PROGRAM:
#include <stdio.h>

#include <string.h>

#include<conio.h>

union Data

char name[20], home_address[20], hostel_address[20], city[20], state[20] , pin[20];

};

void main( )

union Data data;

strcpy(data.name, "Akash");

strcpy(data.home_address, " Plot NO-71,\n HNO 7-80/3/71,\n Phase-2,\n Venkataramana Colony,\n


Dammaiguda");

strcpy(data.hostel_address, "IARE College");

strcpy(data.city, "Hyderabad");

strcpy(data.state, "Telgana");

strcpy(data.pin, "500043");

printf(" Name: %s\n",data.name );

printf(" Home address: %s\n",data.home_address);

printf(" Hostel address: %s\n",data.hostel_address);

printf(" City: %s\n",data.city);

printf("state: %s\n",data.state);

printf("pin : %s\n",data.pin);

getch();

}
INPUT : RANJITH

HNO 7-80/3/71, Phase-2,Venkataramana


Colony,Dammaiguda

IARE College

Hyderabad

Telangana

500043

OUTPUT : Name : RANJITH

House address : HNO 7-80/3/71, Phase-2,Venkataramana


Colony,Dammaiguda

Hostel address : IARE College

City : Hyderabad

State : Telangana

Pincode : 500043
PROGRAM: TO DISPLAY YOUR NAME AND DATE OF BIRTH USING
NESTED STRUCTURE

ALGORITHM:
To display your name and date of birth using nested structure
1. Start

2. Declare nested structure for a person

3. Assign person details to structure

4. Print structure details

5. Stop

PROGRAM:
#include <stdio.h>

#include<conio.h>

struct Employee

char ename[20];

struct date

int date;

int month;

int year;

}dob;

}emp = {"ranjith ",{11,12,1998}};

void main()

{
printf("\nEmployee Name : %s",emp.ename);

printf("\nEmployee DOB : %d/%d/%d", emp.dob.date,emp.dob.month,emp.doj.year);

INPUT : ranjith 11,12,1998

OUTPUT : Employee Name : Akash

Employee DOB : 11/12/1998

You might also like