/*
Date: 17/08/13 13:14
Description: Demonstrates the usage of bitfeilds datatype
*/
#include<stdio.h>
#include<stdlib.h>
int main()
{
struct student{
int rollno:2; //assuming only 2 students [2-bits]=>{00,01,10,11}
int sex :1; //{male=1,female=0}
char name[20];
};
struct student a[4];
int i=0;
for(i=0;i<4;i++)
{
printf("\nenter the data of student-%d\n",i+1);
printf("enter name:") ,scanf("%s",a[i].name);
printf("enter sex (male=1\female=0):") , scanf("%d",a[i].sex);
printf("enter rollno:"); scanf("%d",a[i].rollno);
}
fflush(stdin);
//printfing the data
printf("..........student data...................");
printf("name sex rollno");
printf("\n\n");
for(i=0;i<4;i++)
{
printf("%s",a[i].name);
switch(a[i].sex) //printing sex of the pearson
{
case 0:
printf(" male");
break;
case 1:
printf(" female");
break;
default:
printf(" 0.5");
}
printf(" %d",a[i].rollno);
printf("\n");
}
getchar();
return 0;
}
Date: 17/08/13 13:14
Description: Demonstrates the usage of bitfeilds datatype
*/
#include<stdio.h>
#include<stdlib.h>
int main()
{
struct student{
int rollno:2; //assuming only 2 students [2-bits]=>{00,01,10,11}
int sex :1; //{male=1,female=0}
char name[20];
};
struct student a[4];
int i=0;
for(i=0;i<4;i++)
{
printf("\nenter the data of student-%d\n",i+1);
printf("enter name:") ,scanf("%s",a[i].name);
printf("enter sex (male=1\female=0):") , scanf("%d",a[i].sex);
printf("enter rollno:"); scanf("%d",a[i].rollno);
}
fflush(stdin);
//printfing the data
printf("..........student data...................");
printf("name sex rollno");
printf("\n\n");
for(i=0;i<4;i++)
{
printf("%s",a[i].name);
switch(a[i].sex) //printing sex of the pearson
{
case 0:
printf(" male");
break;
case 1:
printf(" female");
break;
default:
printf(" 0.5");
}
printf(" %d",a[i].rollno);
printf("\n");
}
getchar();
return 0;
}
No comments:
Post a Comment