Define a structure type struct personal that would contain person name, date of joining and salary using this structure to read this information and Display on screen.
Introduction
In this program, we will learn to define a structure type and use it to store data.
Algorithm
- Start
- Declare a structure type 'struct personal' that would contain person name, date of joining and salary.
- Declare an instance of our structure, name it 'person'.
- Get user input of the persons name.
- Get the date they joined.
- Get the salary.
- Print this data to the screen.
- End
Code
Practical-10.c
// First we declare our structure type �struct personal�
struct personal {
char name[20];
int date_of_joining;
int salary;
};
//Now we set out main function
void main(){
//We can now declare an instance of our structure, name it 'person'
struct personal person;
//Now let us get user input of the persons name
printf("Please enter the persons name: ");
scanf("%s", person.name);
//Next we'll get the date they joined
printf("Please enter the persons Date of Joining (int): ");
scanf("%d", &person.date_of_joining);
//And finally the salary
printf("Please enter the persons salary (int): ");
scanf("%d", &person.salary);
//Now we can print this data to the screen
printf("Name: %s\nDate of Joining: %d\nSalary: %d\n", person.name, person.date_of_joining, person.salary);
};
Output
Please enter the persons name: John
Please enter the persons Date of Joining (int): 2021
Please enter the persons salary (int): 100000
Name: John
Date of Joining: 2021
Salary: 100000
Explanation
In this program, we have defined a structure type 'struct personal' that would contain person name, date of joining and salary. We then used this structure to read this information and Display on screen.