0% found this document useful (0 votes)
6 views1 page

CPR Experiment 9

Uploaded by

Backup
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views1 page

CPR Experiment 9

Uploaded by

Backup
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

CPR Experiment 9:

Aim: Write a program to store and display information of a student/employee etc. using structures.
a) Define a structure.
b) Read and store details.
c) Display the stored information.
Theory:
The structure in C is a user-defined data type that can be used to group items of possibly different
types into a single type.
Syntax :
struct structure_name
{
data_type member_name1;
data_type member_name1;
....
};
Exercise:
Write a program to store data of employees within a structure with members as empno, empname,
salary. Accept and display data of 5 employees.
#include <stdio.h>
struct emp {
int empno;
char empname[50];
float salary;
};
void main()
{
struct emp e1[5];
for (int i = 0; i < 5; i++) {
printf("Enter details for employee %d:\n", i + 1);
printf("Employee Number: ");
scanf("%d", &e1[i].empno);
printf("Employee Name: ");
scanf(" %s", e1[i].empname);
printf("Salary: ");
scanf("%f", &e1[i].salary);
}
printf("\nEmployee Details:\n");
printf("=================================\n");
printf("Empno\tEmpName\t\tSalary\n");
for (int i = 0; i < 5; i++)
{
printf("%d\t\t%s\t\t%.2f\n", e1[i].empno,e1[i].empname,e1[i].salary);
}
}

Practical Related Theory Questions:


1. Write difference between array and structure in C.

You might also like