Professional Documents
Culture Documents
Week-8 - Structures: Algorithm
Week-8 - Structures: Algorithm
ALGORITHM:
1. Start
4. Read choice
5. Iif choice = 1 then addition operation will perform and it contains following steps
6. if choice = 2 then multiplication operation will perform and it contains following steps
9. Stop
PROGRAM
#include<stdio.h>
#include<conio.h>
struct complex
{
int real;
int imaginary;
}c1,c2;
void read();
void display();
void main()
read();
display();
add(c1,c2);
sub(c1,c2);
mul(c1,c2);
void read()
scanf("%d%d",&c1.real,&c1.imaginary);
scanf("%d %d",&c2.real,&c2.imaginary);
void display()
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);
c3.real=a.real+b.real;
c3.imaginary=a.imaginary+b.imaginary;
c4.real=a.real-b.real;
c4.imaginary=a.imaginary-b.imaginary;
c5.real=((a.real*b.real)-(a.imaginary*b.imaginary));
c5.imaginary=((a.imaginary*b.real)+(a.real*b.imaginary));
c5=-11+i17
4. Repeat loop 100 employees and calculate gross salary of each employee
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;
Blessington 100.0
Ranjith 1.0
Sanpar 50.0
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 main( ) {
Book1.book_id = 6495407;
Book2.book_id = 6495700;
printBook(Book1);
printBook(Book2);
getch();
INPUT : Nenunaapaithyam
Pawankalyan
Gabbarsingh
Rajamouli
Bahubali series
Book_id : 649507
Book_id : 6495700
PROGRAM:
#include <stdio.h>
#include <string.h>
#include<conio.h>
union Data
};
void main( )
strcpy(data.name, "Akash");
strcpy(data.city, "Hyderabad");
strcpy(data.state, "Telgana");
strcpy(data.pin, "500043");
printf("state: %s\n",data.state);
printf("pin : %s\n",data.pin);
getch();
}
INPUT : RANJITH
IARE College
Hyderabad
Telangana
500043
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
5. Stop
PROGRAM:
#include <stdio.h>
#include<conio.h>
struct Employee
char ename[20];
struct date
int date;
int month;
int year;
}dob;
void main()
{
printf("\nEmployee Name : %s",emp.ename);