RUPAK SEARCH ENGINE

Custom Search

example of structure and nested structure

main()
{
int i;
struct exam /* 1st structure */
{
int prg;
int math;
} ;
struct exam subject;

struct info /* 2nd structure */
{
char sname[20];
int phone;
};
struct info names;
struct details /* 3rd structure */
{
int roll;
struct exam subject; /* 1st nested */
struct info names; /* 2nd nested */
};
struct details students[4]; /* Array of Structure */
clrscr();
for(i=0;i<4;i++)
{
printf("Roll:-%d\n",i+1);
students[i].roll=i+1;
printf("Name:-");
scanf("%s", students[i].names.sname);
printf("Phone:-");
scanf("%d", students[i].names.phone);
printf("Programming:-");
scanf("%d", students[i].subject.prg);
printf("Maths:-");
scanf("%d", students[i].subject.math);
}
clrscr();
printf("Which roll to print? ");
scanf("%d",&i);
i=i-1;
clrscr();
printf("Roll:-%d", students[i].roll);
printf("\nName:-%s", students[i].names.sname);
printf("\nPhone:-%d", students[i].names.phone);
printf("\programming-%d", students[i].subject.prg);
printf("\nMaths:-%d", students[i].subject.math);

getch();
}
/*example of nested structure */
#include
main()
{
int i;
struct exam
{
int prg;
int math;
};
struct exam subjcect;

struct info
{
char sname[20];
int phone;
};
struct info names;

struct details
{
int roll;
struct exam subject;
struct info names;
};
struct details students[4];
clrscr();
for(i=0;i<4;i++)
{
printf("Roll:-%d\n",i+1);
students[i].roll=i+1;
printf("Name:-");
scanf("%s", students[i].names.sname);
printf("Phone:-");
scanf("%d", students[i].names.phone);
printf("Programming:-");
scanf("%d", students[i].subject.prg);
printf("Maths:-");
scanf("%d", students[i].subject.math);
}
clrscr();
printf("Which roll to print? ");
scanf("%d",&i);
i=i-1;
clrscr();
printf("Roll:-%d", students[i].roll);
printf("\nName:-%s", students[i].names.sname);
printf("\nPhone:-%d", students[i].names.phone);
printf("\nProgramming:-%d", students[i].subject.prg);
printf("\nMaths:-%d", students[i].subject.math);
getch();
}

No comments:

Post a Comment