Friday, February 5, 2010

Union in C Language

#include
#include
#include
void main()
{struct student
{
int name;
struct student *next;
}*std,*r,*q;
q='\0';
int m,i,a;
printf("How many students:-\n");
scanf("%d",& m);
printf("Enter %d Elements:\n",m);
for(i=1;i<=m;i++)
{scanf("%d",&a);
std=(struct student*)malloc(sizeof(struct student));
std->name=a;
std->next='\0';
if(q=='\0')
{q=std;
}
else
{r=q;
while(r->next!='\0')
r=r->next;
r->next=std;
}
}
r=q;
while(r!='\0')
{printf("%d \t %d \n",r->name,r->next);
r=r->next;
}
}

No comments:

Post a Comment