Programming for Problem Solving

GTU Practical 50

50. Define a structure type struct personal that would contain person’s name, date of joining and salary using this structure to read this information of 5 people and print the same on screen
#include<stdio.h>  ( this applies in the given code )

#include

struct Personal {
char name[50];
char doj[15];
float salary;
};

int main() {
struct Personal p[5];
for (int i = 0; i < 5; i++) { printf("Enter Name, Date of Joining, Salary: "); scanf(" %[^\n] %[^\n] %f", p[i].name, p[i].doj, &p[i].salary); } printf("\nDetails of 5 People:\n"); for (int i = 0; i < 5; i++) printf("%s %s %.2f\n", p[i].name, p[i].doj, p[i].salary); return 0; }

OUTPUT

Enter Name, Date of Joining, Salary: king1

01/01/2005
5000
Enter Name, Date of Joining, Salary: king2
02/01/2005
5000
Enter Name, Date of Joining, Salary: king3
05/05/2005
6000
Enter Name, Date of Joining, Salary: king4
06/05/2000
9000
Enter Name, Date of Joining, Salary: king5
05/02/2005
10000

Details of 5 People:
king1,01/01/2005,5000 01/01/2005 5000.00
king2 02/01/2005 5000.00
king3 05/05/2005 6000.00
king4 06/05/2000 9000.00
king5 05/02/2005 10000.00

GTU STUDY