Write a c program to demonstrate nested structure
#include<stdio.h>
#include<conio.h>
struct date
{
int day;
int month;
int year;
};
void main()
{
struct employee
{
int empid;
struct date doj;
float salary;
}e;
clrscr();
printf("Enter the employee id: ");
scanf("%d",&e.empid);
printf("Enter the Date of Joining: ");
scanf("%d%d%d",&e.doj.day,&e.doj.month,&e.doj.year);
printf("Enter the salary: ");
scanf("%f",&e.salary);
printf("Employee Information\n");
printf("Employee id=%d\n",e.empid);
printf("Employee Date of Joining=%d-%d-%d\n",e.doj.day,e.doj.month,e.doj.year);
printf("%f",e.salary);
getch();
}
Output:
Enter the employee id: 123
Enter the Date of Joining: 1 6 2005
Enter the salary: 20000
Employee Information
Employee id=123
Employee Date of Joining=1-6-2005
Write a c program to find the area of the room
#include<stdio.h>
#include<conio.h>
struct distance
{
int feet;
float inches;
};
struct room
{
struct distance
length;
struct distance
breadth;
};
void main()
{
struct room drawing;
float l,w;
clrscr();
drawing.length.feet=10;
drawing.length.inches=5.5;
drawing.breadth.feet=20;
drawing.breadth.inches=2.5;
l= drawing.length.feet+ drawing.length.inches/12;
w= drawing.breadth.feet+ drawing.breadth.inches/12;
printf("Area of the drawing room is
%f",l*w,"square feet");
getch();
}
Output:
No comments: