Structures is a unlike datatypes.
#include<stdio.h>
#include<conio.h>
void main()
{
struct sample
{
int a;
float b;
char c;
};
struct sample struct1,struct2;
clrscr();
struct1.a=100;
struct1.b=555.32;
struct1.c=’g’;
struct2=struct1;
printf(“A=%d,B=%f,C=%c\n”,struct2.a,struct2.b, struct2.c);
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
struct date
{
int day;
int month;
int year;
};
struct date dob;
clrscr();
printf(“Enter the date of birth:”);
scanf(“%d”,&dob.day);
printf(“Enter the month of birth:”);
scanf(“%d”,&dob.month);
printf(“Enter the year of birth:”);
scanf(“%d”,&dob.year);
printf(“Date of birth=”);
printf(“%d/”,dob.day);
printf(“%d/”,dob.month);
printf(“%d.”,dob.year);
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
struct address
{
char name[10];
char street[10];
char city[10];
char pin[7];
};
struct address my;
clrscr();
printf(“Enter the name:”);
gets(my.name);
printf(“Enter the street name:”);
gets(my.street);
printf(“Enter the city name:”);
gets(my.city);
printf(“Enter the pincode:”);
gets(my.pin);
printf(“Address=\n”);
printf(“%s\n”,my.name);
printf(“%s\n”,my.street);
printf(“%s\n”,my.city);
printf(“%s\n”,my.pin);
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
struct address
{
char name[20];
char add[20];
char city[10];
long int phone;
};
struct emp
{
int eno;
struct address a;
struct emp e[100];
int i;
clrscr();
printf(“Enter empno,name,address,city,phone\n”);
for(i=0;i<2;i++)
{
scanf(“%d%s%s%s%ld”,&e[i].eno,&e[i].a.name, &e[i].a.add,e[i].a.city,&e[i].a.phone);
}
line();
printf(“Eno\tName\t\tAddress\t\tCity\tPhone\n”);
line();
for(i=0;i<2;i++)
{
printf(“%d\t%s\t\t%s\t%s\t%ld\n”,e[i].eno,e[i]. a.name,e[i].a.add,e[i].a.city,e[i].a.phone);
}
line();
getch();
}
line()
{
printf(“*********************************\n”);
}
#include<stdio.h>
#include<conio.h>
void main()
{
struct person
{
char per_name[25];
int age;
}r[20];
int i,sno;
for(i=0;i<20;i++)
{
clrscr();
printf(“Enter person name:”);
gets(r[i].per_name);
printf(“\n Age:”);
scanf(“%d”,&r[i].age);
}
clrscr();
printf(“\n\n Eligible candidate name & age list\n”);
printf(“*********************************\n”);
printf(“Sno\tPerson Name\t\tAge\n”);
printf(“*********************************\n”);
sno=1;
for(i=0;i<20;i++)
{
if(r[i].age>=18)
{
printf(“\n %d\t%s\t\t%d”,sno.r[i].per_name,r[i].age);
sno++;
}
}
printf(“*********************************\n”);
getch();
}
No comments:
Post a Comment