0% found this document useful (0 votes)
7 views7 pages

Array of Structure

Programming in C

Uploaded by

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

Array of Structure

Programming in C

Uploaded by

Akanksha Bisht
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

Array of Structure

#include<stdio.h> scanf("%s %d %f",s1.name,&s1.id,&s1.marks);


struct student printf("Enter the name, id, and marks of student 2 ");
scanf("%s %d %f",s2.name,&s2.id,&s2.marks);
{
char name[20]; printf("Enter the name, id, and marks of student 3 ");
scanf("%s %d %f",s3.name,&s3.id,&s3.marks);
int id;
float marks;
}; printf("Printing the details....\n");
printf("%s %d %f\n",s1.name,s1.id,s1.marks);
void main() printf("%s %d %f\n",s2.name,s2.id,s2.marks);
{ printf("%s %d %f\n",s3.name,s3.id,s3.marks);
}
struct student s1,s2,s3;
printf("Enter the name, id,
and marks of student 1 ");
Array of Structures
• An array of structures in C can be defined as the collection of multiple
structures variables where each variable contains information about
different entities.
#include<stdio.h> for(i=0;i<5;i++){
#include <string.h> printf("\nEnter Rollno:");
scanf("%d",&st[i].rollno);
struct student{
printf("\nEnter Name:");
int rollno; scanf("%s",&st[i].name);
char name[10]; }
}; printf("\nStudent Information List:");
int main(){ for(i=0;i<5;i++){
printf("\nRollno:%d, Name:
int i;
%s",st[i].rollno,st[i].name);
struct student st[5]; }
printf("Enter Records return 0;
of 5 students"); }
Passing Array of structure to
function
#include<stdio.h>
struct Employee
{
int id;
char name[20];
float salary;
};
struct Employee MaxSalaryEmployee(struct employee e[], int n)
{
struct Employee m;
int i;
m = e[0];
for(i=0;i<n;i++)
{
if(e[i].salary > m.salary)
{
m = e[i];
}
}
return m;
void main()
{
struct Employee e[5], max;
int i;
for(i=0; i<5; i++)
{
printf(“Please enter id, name and salary”);
scanf(“%d%s%f”, &e[i].id, &e[i].name, &e[i].salary);
}
max = MaxSalaryEmployee(e, 5);
printf(“Employee having max salary\n”);
printf(“%d\t%s\t%f”, max.id, max.name, max.salary);
}

You might also like