Problem 50

author
By Supreme2023-03-16
Problem Statement :
Define a structure type struct personal that would contain person name, date of joining and salary using this structure to read this information of 5 people and print the same on screen.
Code:

#include <stdio.h>

struct personal {
char name[50];
char doj[20];
float salary;
};

int main() {
/*50. Define a structure type struct personal that would contain person name, date of joining
and salary using this structure to read this information of 5 people and print the same on
screen.*/

printf("\tInformation Form\n");
printf("========================================\n");

struct personal person[5];
int i;

for (i = 0; i < 5; i++) {
printf("\n\nEnter name for person %d: ", i+1);
scanf("%s", person[i].name);
printf("\nEnter date of joining for person %d: ", i+1);
scanf("%s", person[i].doj);
printf("\nEnter salary for person %d: ", i+1);
scanf("%f", &person[i].salary);
}

for (i = 0; i < 5; i++) {
printf("------------------------------------------\n");
printf("\nFor Person %d : ",i+1);
printf("\n\nName: %s\n", person[i].name);
printf("\nDate of Joining: %s\n", person[i].doj);
printf("\nSalary: %.2f\n", person[i].salary);
printf("------------------------------------------\n");
}

return 0;
}

Description :
  • This program defines a structure type called "personal" that contains three members: two character arrays called "name" and "doj" with lengths of 50 and 20 respectively, and a floating-point number called "salary".
  • The program then prompts the user to enter information for 5 people. It creates an array of 5 "personal" structures called "person", and uses a "for" loop to iterate over each element of the array. For each person, it prompts the user to enter their name, date of joining, and salary using the "scanf" function.
  • After all the information is entered, the program uses another "for" loop to print out the entered information in a formatted manner for each person. The program ends by returning 0.
Output Image:
Output-image

© Copyright 2022. All right reserved, GTU Coder.