Programming in C 312303 Manual Practical No 20 Implement ‘Array of Structure’ in C

 Programming in C 312303 Manual Practical No 20 Implement ‘Array of Structure’ in C Answer

In this Programming in C 312303 Manual practical no.20, we are going to learn how to Implement ‘Array of Structure’ in C and answer the practical related questions.

Programming in C 312303 Manual Practical No 20 Implement ‘Array of Structure’ in C
Programming in C 312303 Manual Practical No 20 Implement ‘Array of Structure’ in C

An array of structures in C is like having a bunch of containers that hold different kinds of information about different things, like people or animals. It’s a way to keep track of lots of different things all together. By using arrays of structures, students can write programs that organize and store information helpfully.

Exercise

1.Accept and Display 10 employees ’s information using structure.
Answer:
#include <stdio.h>
#include <string.h> // For string operations (strcpy)
struct Employee {
    int id;
    char name[50];
    float salary;
};
int main() {
    struct Employee employees[10]; // Array of 10 Employee structures
    // Input loop for employee information
    for (int i = 0; i < 10; i++) {
        printf(“nEnter details for Employee %d:n”, i + 1);
        printf(“ID: “);
        scanf(“%d”, &employees[i].id);
        printf(“Name: “);
        // Use fgets to avoid buffer overflow issues with names
        fgets(employees[i].name, sizeof(employees[i].name), stdin);
        // Remove trailing newline character from name (optional)
        employees[i].name[strcspn(employees[i].name, “n”)] = ‘
Suraj Diware
Suraj Diware

Hi everyone, I'm Suraj Diware, and I'm passionate about helping students succeed in MSBTE programs. This blog is dedicated to providing clear and concise explanations of MSBTE curriculum topics, along with practical tips and resources to support your learning journey.

Articles: 703

4 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *