code:
#include<stdio.h>
struct s1
{
int roll;
float gpa;
};
struct s2
{
char name[100];
char classe[20];
struct s1 info;
};
int main()
{
struct s2 student= {"Zaki","Twelve",12,5.0};
printf("Name: %s\n",student.name);
printf("Class %s\n",student.classe);
printf("Roll: %d\n",student.info.roll);
printf("GPA %f\n",student.info.gpa);
return 0;
}
struct some other beautiful example:
code:
#include<stdio.h>
struct employee
{
char name[100];
int salary;
struct salary
{
int hour;
int day;
int cost;
} d;
};
int main()
{
struct employee person;
printf("Enter employee name:");
gets(person.name);
printf("Enter per day work hour:");
scanf("%d",&person.d.hour);
printf("Enter per hour cost:");
scanf("%d",&person.d.cost);
printf("Enter work day in a month:");
scanf("%d",&person.d.day);
person.salary=person.d.hour*person.d.cost*person.d.day;
printf("%s's total salary is %d.",person.name,person.salary);
return 0;
}