Write a program to pass an array of structure to the function.
#include<iostream>
using namespace std;
struct student
{
char fname[50];
char sname[50];
int id;
unsigned int phone;
};
void fun(student[]);
main()
{
student s[3];
for(int i=0; i<3; i++)
{
cout<<"enter the data of student"<<i+1<<endl;
cout<<"enter the 1st name of the student"<<endl;
cin>>s[i].fname;
cout<<"enter the 2nd name of the student"<<endl;
cin>>s[i].sname;
cout<<"enter the id of the student :"<<endl;
cin>>s[i].id;
cout<<"enter the phone number of the student:"<<endl;
cin>>s[i].phone;
}
fun(s);
}
void fun(student r[])
{
system("CLS");
cout<<" name \t id \t phone "<<endl;
for(int i=0; i<3; i++)
{
cout<<i+1<<" "<<r[i].fname<<" "<<r[i].sname<<" \t "<<r[i].id<<" \t "<<r[i].phone<<endl;
}
}
0 on: "Write a program to pass an array of structure to the function."