Professional Documents
Culture Documents
Date : 7/02/2021
Aim: Create a structure which holds various attributes (e.g. name, id,
basic_salary, DA%, HRA%, total_salary etc.) of an employee. Write a program
which allows you to scan these (except total_salary) attributes for 3 employees.
The program should support following operations:
Methodology followed:
#include <stdio.h>
struct employee
{ char name[10];
int id;
float Basic_salary;
};
void main()
{
float T1,T2,T3,DA1,HRA1,DA2,HRA2,DA3,HRA3,Basic_salary;
struct employee e,e1,e2;
printf("\n Input Values \n");
printf("\nEnter the values(id,salary):");
scanf("%d %f",&e.id,&e.Basic_salary);
printf("\nEnter the name:");
scanf("%s",e.name);
printf("\nEnter the values(id,salary):");
scanf("%d %f",&e1.id,&e1.Basic_salary);
printf("\nEnter the name:");
scanf("%s",e1.name);
printf("\nEnter the values(id,salary):");
scanf("%d %f",&e2.id,&e2.Basic_salary);
printf("\nEnter the name:");
scanf("%s",e2.name);
DA1=0.5*(e.Basic_salary);
HRA1=0.1*(e.Basic_salary);
DA2=0.5*(e1.Basic_salary);
HRA2=0.1*(e1.Basic_salary);
DA3=0.5*(e2.Basic_salary);
HRA3=0.1*(e2.Basic_salary);
printf("\n%s %d %f %f %f\n",e.name,e.id,e.Basic_salary,DA1,HRA1);
printf("\n%s %d %f %f %f\n",e1.name,e1.id,e1.Basic_salary,DA2,HRA2);
printf("\n%s %d %f %f %f\n",e2.name,e2.id,e2.Basic_salary,DA3,HRA3);
T1=e.Basic_salary+DA1+HRA1;
T2=e1.Basic_salary+DA2+HRA2;
T3=e2.Basic_salary+DA3+HRA3;
printf("\n THE TOTAL SALARY \n");
printf("\nThe Total is of %s is %f.\n",e.name,T1);
printf("\nThe Total is of %s is %f.\n",e1.name,T2);
printf("\nThe Total is of %s is %f.\n",e2.name,T3);
printf("\n THE MAXIMUM SALARY \n");
if(T1>T2 && T1>T3)
{
printf("\n The %s has maxium salary %f.\n",e.name,T1);
}
else if(T2>T3 && T2>T1)
{
printf("\n The %s has maxium salary %f.\n",e1.name,T2);
}
else
{
printf("\n The %s has maxium salary %f.\n",e2.name,T3);
}
}
Theoretical Principles Used: Here the concept of struct is used for fetching the
details of employee for calculating the final salary. Also if else condition is used
to compare the salary of the entered salary of the employee.
Output:put Values
Enter the values(id,salary):1 100000
Enter the name:darshil
Enter the values(id,salary):2 500000
Enter the name:mohit
Enter the values(id,salary):3 600000
Enter the name:dixit
darshil 1 100000.000000 50000.000000 10000.000000
mohit 2 500000.000000 250000.000000 50000.000000
dixit 3 600000.000000 300000.000000 60000.000000
THE TOTAL SALARY
The Total is of darshil is 160000.000000.
The Total is of mohit is 800000.000000.
The Total is of dixit is 960000.000000.
THE MAXIMUM SALARY
The dixit has maxium salary 960000.000000.
Practical No.: 8-B
Aim: Write a structure to accept item information such as name, quantity and
unit price. Structure should take information about 5 items. Create a user
defined function that calculates the cost of each item. Print details of each item
such as: Name Quantity Price Cost Notebook
5 50.0 250.0 Pen Drive 2 500.0
1000.0 Pen 20 5.0 100.0
Methodology followed:
#include <stdio.h>
struct stationary
{
char name[10];
int quantity;
float Eprize;
};
float prize(float a,float b)
{
float c;
c=a*b;
return(c);
}
void main()
{
float T1,T2,T3,T4,T5;
struct stationary s,s1,s2,s3,s4;
printf("\n Input Values \n");
printf("\nEnter the Values(quantity,prize):");
scanf("%d %f",&s.quantity,&s.Eprize);
printf("\nEnter the name:");
scanf("%s",s.name);
printf("\nEnter the Values(quantity,prize): ");
scanf("%d %f",&s1.quantity,&s1.Eprize);
printf("\nEnter the name:");
scanf("%s",s1.name);
printf("\nEnter the Values(quantity,prize): ");
scanf("%d %f",&s2.quantity,&s2.Eprize);
printf("\nEnter the name:");
scanf("%s",s2.name);
printf("\nEnter the Values(quantity,prize): ");
scanf("%d %f",&s3.quantity,&s3.Eprize);
printf("\nEnter the name:");
scanf("%s",s3.name);
printf("\nEnter the Values(quantity,prize): ");
scanf("%d %f",&s4.quantity,&s4.Eprize);
printf("\nEnter the name:");
scanf("%s",s4.name);
T1= prize(s.quantity,s.Eprize);
T2= prize(s1.quantity,s1.Eprize);
T3= prize(s2.quantity,s2.Eprize);
T4= prize(s3.quantity,s3.Eprize);
T5= prize(s4.quantity,s4.Eprize);
printf("\nThe Output is:\n");
printf("\n%s %d %f %f",s.name,s.quantity,s.Eprize,T1);
printf("\n%s %d %f %f",s1.name,s1.quantity,s1.Eprize,T2);
printf("\n%s %d %f %f",s2.name,s2.quantity,s2.Eprize,T3);
printf("\n%s %d %f %f",s3.name,s3.quantity,s3.Eprize,T4);
printf("\n%s %d %f %f",s4.name,s4.quantity,s4.Eprize,T5);
}
Input-Output:
Input Values
Enter the Values(quantity,prize):5 10
Enter the name:pen
Enter the Values(quantity,prize): 10 20
Enter the name:scale
Enter the Values(quantity,prize): 50 3
Enter the name:penciel
Enter the Values(quantity,prize): 10 50
Enter the name:book
Enter the Values(quantity,prize): 6 3
Enter the name:sticker
The Output is:
pen 5 10.000000 50.000000
scale 10 20.000000 200.000000
penciel 50 3.000000 150.000000
book 10 50.000000 500.000000
sticker 6 3.000000 18.000000
Aim: Write a structure for a complex number which has a real part and an
imaginary part. Add the 2 complex numbers, store it in another complex
number using user defined function and display the result as a complex
number.
Methodology followed:
#include<stdio.h>
typedef struct complex
{
float real;
float imag;
}complex;
complex Add(complex a,complex b);
void main()
{
complex a,b,ans;
printf("\nTHE FIRST NUMBER\n");
printf("\nEnter the values for First complex number:");
scanf("%f %f",&a.real,&a.imag);
printf("\nTHE SECOND NUMBER\n");
printf("\nEnter the values for Second complex number:");
scanf("%f %f",&b.real,&b.imag);
ans=Add(a,b);
printf("Ans is=%f+i%f",ans.real,ans.imag);
}
complex Add(complex a,complex b)
{
complex var;
var.real=a.real+b.real;
var.imag=a.imag+b.imag;
return(var);
}
Theoretical Principles used:Here we have learnt how to use the struct
function for creating the complex number. Here real and imaginary part of the
complex is fetch from the user and addition of real part and imaginary parts is
carried out by using user defined function.
Output:
THE FIRST NUMBER
Enter the values for First complex number:5 6
THE SECOND NUMBER
Enter the values for Second complex number:2 1
Ans is=7.000000+i7.000000
Conclusion:
Signature of Teacher: