/* write a program to display the
information about a student using
structure*/
#include<stdio.h>
#include<conio.h>
Void main()
{
Struct student
{
Char name[20];
Int age;
Int roll;
Float fee;
};
Struct student s1;
Clrscr();
Printf(\n enter the data of a s1);
Scanf(%s%d%d%f,&s1.name,&s1.age,&s1.roll,&s1.fee);
Printf(\n name=%s,s1 name);
Printf(\n age =%d,s1 age);
Printf(\n roll=%d,s1 roll);
Print(\n fee=%f,s1 fee);
Getch();
}
Output:
Enter the data of student
Name= jasvir
Age=20
Roll no= 236
Fee= 22000
/* write a program to nexted structure*/
#include<stdio.h>
#include<conio.h>
Void main()
{
Struct dob
{
Int date;
Int month;
Int year;
};
Struct student;
{
Char name[20];
Int roll;
Float fee;
Struct dob d1;
};
Struct student s1;
Clrscr();
Printf(\n enter the data of a s1);
Scanf(%%d%f,&s1.name,&s1.roll,&s1.fee);
Printf(\n name=%s,s1 name);
Printf(\n roll=%d,s1 roll);
Print(\n fee=%f,s1 fee);
Printf(\n enter the data of d1);
Scanf(%d%d%d,&d1.day,&d1.month,&d1.year);
Printf(\n day=%d,d1 day);
Printf(\n month=%d,d1 month);
Printf(\n year=%d,d1 year);
Getch();
}
Output
Enter the data of a student
Enter the name: jasvir aujla
Enter the roll no: 01
Enter the fee: 22000
Enter the date of birth day month year: 16 12 92
Record of a student is
Jasvir aujla 01 22000 16 12 92
/* write a program for array of structure*/
#include<stdio.h>
#include<conio.h>
Void main( )
{
struct student
{
Char name[20];
Char address[40];
Int rollno;
};
Struct student s1[5];
Clrscr();
Int i;
printf(enter the data of s1);
for(i=0; i<5; i++)
{
scanf(%s%s%d,&s1[i].name,&s1[i].address,&s1[i].rollno);
}
for(i=0; i<5; i++)
{
printf(\n name=%s,s1[i].name);
printf(\n address=%s,s1[i].address);
printf(\n rollno=%d,s1[i].rollno);
}
getch();
Output:
enter the data of student:
sangrur 1 2 3 4 5
ram sham mohan Sharma jot dhuri sunam patran barnala
name= ram
address=dhuri
rollno=1
name=sham
adderss=sunam
rollno=2
name=mohan
address=patran
rollno=3
name =sharma
address=barnala
rollno=4
name=jot
address=sangrur
rollno=5
/* write a program for array with in structure*/
#include<stdio.h>
#include<conio.h>
Void main( )
{
struct student
{
Char name[20];
Int rollno;
Int marks[5];
};
Struct student s1;
Clrscr();
Int i;
Printf(\n entrt thr data of s1);
Scanf(%s%d,&s1.name,&s1.rollno);
For(i=0;i<=4;i++)
{
Scanf(%d,&s1.marks[i]);
}
Printf(\n name=%S,s1 name);
Printf(\n rollno=%d,s1 rollno);
For(i=0;i<=4;i++)
{
Printf(\n marks=%d,S1 marks);
}
Getch();
}
Output:
Enter the data of student
Name=jasvir
Rollno=5464
Marks=56
56
89
78
99
/*write a program of union*/
#include<stdio.h>
#include<conio.h>
Void main()
{
union student
{
Char name[20];
Int age;
Int roll;
Float fee;
};
union student s1;
Clrscr();
Printf(\n enter the data of a s1);
Scanf(%s%d%d%f,&s1.name,&s1.age,&s1.roll,&s1.fee);
Printf(\n name=%s,s1 name);
Printf(\n age =%d,s1 age);
Printf(\n roll=%d,s1 roll);
Print(\n fee=%f,s1 fee);
Getch();
}
Output:
Enter the data of student
Name= jasvir
Age=20
Roll no= 236
Fee= 22000
/*write the program to print address of the
variable using pointer*/
#include<stdio.h>
#include<conio.h>
void main()
{
int i=5,*j;
j= &I;
printf(\n enter the value of i=%d,i);
printf(\n enter the address of i=%u,&i);
printf(\n enter the address of i=%u,j);
printf(\n enter the value of i=%d,*j);
getch();
output:
the value of i=5
the address of i=2002
the address of i=2002
the value of i= 5