Friday, May 30, 2014

WRITE A PROGRAMME TO ILLUSTRATE THE DIFFERENT WAYS OF DECLARATION AND INITIALIZATION OF STRUCTURE VARIABLE BY STORING INFORMATION OF THREE STUDENT

#include<conio.h>
#include<stdio.h>
#include<strin.h>
void main()
{
//Different ways of declaring structure variable
struct info
{
int sno;
char name[20];
char add[20];
}s1,s2;

/*struct
{
int sno;
char name[20];
char add[20];
}s3,s4;*/

//struct info s5,s6;

//Different ways of initialising structure varibles
struct info stu1={1,"ajay","dehradun"};

struct info stu2,stu3;
clrscr();
stu2.sno=2;
//stu2.name="rashmi";//wrong
strcpy(stu2.name,"rashmi");
//printf("\n%u",stu2.name);
//printf("\n%u",stu2.sno);
strcpy(stu2.add,"delhi");

printf("enter the sno,name and add of third student\n");
scanf("%d%s%s",&stu3.sno,stu3.name,stu3.add);

printf("\ndetails of students are\n");
printf("\ndetails of 1st stu-> %d\t%s\t%s",stu1.sno,stu1.name,stu1.add);
printf("\ndetails of 2nd stu-> %d\t%s\t%s",stu2.sno,stu2.name,stu2.add);
printf("\ndetails of 3rd stu-> %d\t%s\t%s",stu3.sno,stu3.name,stu3.add);



getch();
}

No comments:

Post a Comment