Back To C++ Structures
//program to create a structure student and calculate percentage based on marks (example of array within a structure) #include
#include
struct student { int rollno; char name[20]; int marks[5]; float percentage; }; void main() { clrscr(); student s; float temp=0; int i; cout<<"\nenter rollno of student "; cin>>s.rollno; cout<<"\nenter name of student "; cin>>s.name; for(i=0;i<5;i++) { cout<<"\nenter marks in subject "<
>s.marks[i]; temp=temp+s.marks[i]; } cout<<"\ndisplaying the data "; cout<<"\nrollno of student is "<