0% found this document useful (0 votes)
13 views

Exercise 8 - Structures

Uploaded by

pavanmay227597
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Exercise 8 - Structures

Uploaded by

pavanmay227597
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Programming in C – Practical Exercise 8

Exercise 8 Structures

Write a C program – using structures for reading the employee details


like employee name, date of joining and salary and also to compute
Total salary outgo for a month.

Objective:
The objective of this program is to:
Read the employee details like employee name, date of joining and salary.
And display the total salary of the particular month.

Program Code:
struct personal
{
char name[20];
int day;
char month[10];
int year;
float salary;
};
main()
{
struct personal person [10];
int totalsalary=0;
int n,i;
char month;
printf (“enter number of employees”);
scanf (“%d”,&n);
for (i=1; i<=n; i++)
{
printf("Input Values\n");
scanf("%s %d %s %d %f",
person.name,
&person.day,
person.month,
&person.year,
&person.salary);

Sikkim Manipal University B2111 Page No.: 15


Programming in C – Practical Exercise 8

printf("%s %d %s %d %f\n",
person.name,
person.day,
person.month,
person.year,
person.salary);
}
Printf(“enter the month for total salary”);
Scanf(“%s”,month)
For(i=1; i<n; i++)
{
t = strcmp(person.month[i], month)
if (t=0)
total salary = total salary + person. salary[i]
}
Printf (“the total salary for giving month = %d”, total salary);
}

Expected Output:
Input Values
Chandu 25 January 2012 5500
Kishore 20 January 2012 5500

Output values
Chandu 25 January 2012 5500.00
Kishore 20 January 2012 5500.00

enter the month for total salary


January
the total salary for giving month 11000.00

Sikkim Manipal University B2111 Page No.: 16

You might also like