English, asked by kavyaboppudi123, 6 months ago

write a c program to read and display information of student of a class using array of structures.the information should include name,roll_num, and CGPA of the structure

Answers

Answered by parthpatil0505
3

Explanation:

Structure is collection of different data type. An object of structure represents a single record in memory, if we want more than one record of structure type, we have to create an array of structure or object.

As we know, an array is a collection of similar type, therefore an array can be of structure type. You can store “n” number of students record by declaring structure variable as ‘struct student record[n]“, where n can be 1000 or 5000 etc.

This program is used to store and access “name, roll no. and marks ” for many students using array of structures members.

Syntax for declaring structure array : :

struct struct-name

{

datatype var1;

datatype var2;

– – – – – – – – – –

– – – – – – – – – –

datatype varN;

};

struct struct-name obj [ size ];

Accessing Structure Members

To access any member of a structure, we use the member access operator (.). The member access operator is coded as a period between the structure variable name and the structure member that we wish to access. You would use the keyword struct to define variables of structure type.

Below is the source code for C Program to enter Student Details using array of structures which is successfully compiled and run on Windows System to produce desired output as shown below :

SOURCE CODE : :

C

/* Program to understand array of structures*/

#include<stdio.h>

struct student {

char name[20];

int rollno;

float marks;

};

int main( )

{

int i,n;

printf("Enter how many records u want to store :: ");

scanf("%d",&n);

struct student stuarr[n];

printf("Enter name, roll no. and marks Below :: \n");

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

{

printf("\nEnter %d record :: \n",i+1);

printf("Enter Name :: ");

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

printf("Enter RollNo. :: ");

scanf("%d",&stuarr[i].rollno);

printf("Enter Marks :: ");

scanf("%f",&stuarr[i].marks);

}

printf("\n\tName\tRollNo\tMarks\t\n");

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

printf("\t%s\t%d\t%.2f\t\n", stuarr[i].name, stuarr[i].rollno, stuarr[i].marks);

return 0;

}

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

/* Program to understand array of structures*/

#include<stdio.h>

struct student {

char name[20];

int rollno;

float marks;

};

int main( )

{

int i,n;

printf("Enter how many records u want to store :: ");

scanf("%d",&n);

struct student stuarr[n];

printf("Enter name, roll no. and marks Below :: \n");

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

{

printf("\nEnter %d record :: \n",i+1);

printf("Enter Name :: ");

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

printf("Enter RollNo. :: ");

scanf("%d",&stuarr[i].rollno);

printf("Enter Marks :: ");

scanf("%f",&stuarr[i].marks);

}

printf("\n\tName\tRollNo\tMarks\t\n");

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

printf("\t%s\t%d\t%.2f\t\n", stuarr[i].name, stuarr[i].rollno, stuarr[i].marks);

return 0;

}

OUTPUT : :

C

Enter how many records u want to store :: 5

Enter name, roll no. and marks Below ::

Enter 1 record ::

Enter Name :: John

Enter RollNo. :: 1

Enter Marks :: 67

Enter 2 record ::

Enter Name :: Snow

Enter RollNo. :: 2

Enter Marks :: 88

Enter 3 record ::

Enter Name :: Hodor

Enter RollNo. :: 3

Enter Marks :: 55

Enter 4 record ::

Enter Name :: Ramsey

Enter RollNo. :: 4

Enter Marks :: 77

Enter 5 record ::

Enter Name :: Stark

Enter RollNo. :: 5

Enter Marks :: 99

Name RollNo Marks

John 1 67.00

Snow 2 88.00

Hodor 3 55.00

Ramsey 4 77.00

Stark 5 99.00

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

Enter how many records u want to store :: 5

Enter name, roll no. and marks Below ::

Enter 1 record ::

Enter Name :: John

Enter RollNo. :: 1

Enter Marks :: 67

Enter 2 record ::

Enter Name :: Snow

Enter RollNo. :: 2

Enter Marks :: 88

Enter 3 record ::

Enter Name :: Hodor

Enter RollNo. :: 3

Enter Marks :: 55

Enter 4 record ::

Enter Name :: Ramsey

Enter RollNo. :: 4

Enter Marks :: 77

Enter 5 record ::

Enter Name :: Stark

Enter RollNo. :: 5

Enter Marks :: 99

Name RollNo Marks

John 1 67.00

Snow 2 88.00

Hodor 3 55.00

Ramsey 4 77.00

Stark 5 99.00

If you found any error or any queries related to the above program or any questions or reviews , you wanna to ask from us ,you may Contact Us through our contact Page or you can also comment below in the comment section.We will try our best to reach upto you in the short interval.

Thanks for reading the post.

4

Article Rating

Related posts:

Write a C program count total number of duplicate elements in an array

C Program to print value and address of elements of an array without pointer

Write a C program to replace all Even elements by 0 and Odd by 1

Category: Arrays Programs C Programming Tags: c_arrays

Post navigation← Write a C Program to display student details using structure membersWrite a C Program to understand arrays within structures

Similar questions