0% found this document useful (0 votes)
15 views

Task 11

Uploaded by

kripalaalal4
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Task 11

Uploaded by

kripalaalal4
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Task 11: Problem using Array of structures

Problem Statement: Design a C program that manages student information by defining a


Student structure that includes the student's name, ID, and Grade Point Average. The
program should allow users to input details for n students and then display the information.

Aim:
To write a C program to get students details and display it using array of structure.

Algorithm:
Step 1: Start.

Step 2: Declare a structure named Student with attributes: name, id, and GPA.

Step 3: Declare an array of structure variable for students with size n.

Step 4: Read the values of the structure members for n students using a loop.

Step 5: Print the members of the structure Student using a loop.

Step 6: Stop.

Program:
#include <stdio.h>

// Define a structure to store student information

struct student

char name[50];

int id;

float GPA;

};

int main()

// Define an array of structures to hold 3 students

struct student s[30];


int n;

printf(" Enter the number of students: ");

scanf("%d",&n);

// Input data for each student

for (int i = 0; i < n; i++)

printf("Enter details for student %d:\n", i + 1);

printf("Name: ");

scanf("%s", s[i].name);

printf("id: ");

scanf("%d", &s[i].id);

printf("Grade Point Average: ");

scanf("%f", &s[i].GPA);

printf("\n");

// Display the details of each student

printf("Student Information:\n");

printf("Name \t id \t GPA\n");

for (int i = 0; i < n; i++)

printf("%s\t%d\t%0.2f\n", s[i].name,s[i].id,s[i].GPA);

}
Sample output:
Enter the number of students: 3

Enter details for student 1:

Name: Alice

id: 101

Grade Point Average: 8.5

Enter details for student 2:

Name: Bob

id: 102

Grade Point Average: 7.8

Enter details for student 3:

Name: Charlie

id: 103

Grade Point Average: 8

Student Information:

Name id GPA

Alice 101 8.50

Bob 102 7.80

Charlie 103 8.00

Result:

Thus the C program for displaying student details using array of structure has been
successfully completed.

You might also like