define a structure type,struc personal that would contain person name,date of joining and salary.
Answers
Definition of structure for the given structure type is as follows :-
struct personal
{
char person_name[100];
char join_date[100];
float salary;
};
struct personal p;
A complete C program is shown to get a better understanding of defining structure, taking input for structure types and printing them.
#include <stdio.h>
struct personal
{
char person_name[100];
char join_date[100];
float salary;
};
struct personal p;
int main()
{
printf("Enter Name of the person :- ");
scanf("%s",p.person_name);
printf("Enter Joining Date of the person :- ");
scanf("%s",p.join_date);
printf("Enter Salary of the person :- ");
scanf("%f",&p.salary);
printf("\nName of the person :- %s\n",p.person_name);
printf("Joining Date of the person :- %s\n",p.join_date);
printf("Salary of the person :- %0.2f\n",p.salary);
}
Answer:
#include <stdio.h>
struct person
{
char name[20];
char doj[10];
float salary;
}p[5];
int main(void)
{
int i=0;
for(i=0;i<5;i++)
{
printf("\n Enter Person Name : ");
scanf("%s",p[i].name);
printf("\n Enter Person Date of Joining (dd-mm-yyyy) : ");
scanf("%s",p[i].doj);
printf("\n Enter Person Salary : ");
scanf("%f",&p[i].salary);
}
for(i=0;i<5;i++)
{
printf("\n Person %d Detail",i+1);
printf("\n Name = %s",p[i].name);
printf("\n DOJ = %s",p[i].doj);
printf("\n Salary = %.2f",p[i].salary);
printf("\n");
}
return 0;
}
Explanation: