/*write a c program using data structure to accept the details of employee
from the user and display it on screen using dynamic memory allocation*/
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<alloc.h>
void main()
{
int i=-1,j;
char ch='y';
struct emp
{
int eno;
char ename[30];
int salary;
};
struct emp *p;
clrscr();
p=(struct emp *)malloc(sizeof(struct emp));
while(ch=='y'||ch=='Y')
{
i++;
printf("\nenter the employee id:-");
scanf("%d",&p[i].eno);
printf("\nenter the employee name:-");
scanf("%s",&p[i].ename);
printf("\nenter the salary:-");
scanf("%d",&p[i].salary);
printf("\ndo you want to continue(Y|N):-");
scanf("%s",&ch);
}
printf("\ninfromation about employees\n");
printf("employee id| employeename| salary");
printf("\n-----------|-------------|-------\n");
for(j=0;j<=i;j++)
{
printf("\n%d | %s | \%d",p[j].eno,p[j].ename,p[j].salary);
}
getch();
}
/*--------------------OUTPUT--------------
enter the employee id:-101
enter the employee name:-peersaab
enter the salary:-12000
do you want to continue(Y|N):-y
enter the employee id:-102
enter the employee name:-santosh
enter the salary:-15000
do you want to continue(Y|N):-n
infromation about employees
employee id| employeename| salary
-----------|-------------|-------
101 | peersaab | 12000
102 | santosh | 15000
*/
No comments:
Post a Comment