Example program for array of structure in C C++

 

Coding in C

#include<stdio.h>

struct student
{
char grade;
int marks;
float percent;
};

int main()
{
struct student s[3];
int i;
for(i=0;i<3;i++)
{
printf(“Enter Grade : “);
scanf(“%c”,&s[i].grade);
printf(“Enter Marks : “);
scanf(“%d”,&s[i].marks);
printf(“Enter Percent : “);
scanf(“%f”,&s[i].percent);
}
for(i=0;i<3;i++)
{
printf(“The Grade is : %c”,s[i].grade);
printf(“\nThe Marks is : %d”,s[i].marks);
printf(“\nThe Percent is: %f”,s[i].percent);
}

return 0;
}

 

Coding in C++

#include<iostream>
using namespace std;

struct student
{
char grade;
int marks;
float percent;
};

int main()
{
student s[3];
int i;

for(i=0;i<3;i++)
{
cout<<“Enter Grade : “;
cin>>s[i].grade;
cout<<“Enter Marks : “;
cin>>s[i].marks;
cout<<“Enter Percent : “;
cin>>s[i].percent;
}

for(i=0;i<3;i++)
{
cout<<“The Grade is : “<<s[i].grade<<endl;
cout<<“The Marks is : “<<s[i].marks<<endl;
cout<<“The Percent is : “<<s[i].percent<<endl;
}

return 0;
}

 

Output

Example program for array of structure in C C++

 

Published by

admin

I am a computer teacher, programmer and web developer