Saturday 12 March, 2011

In a program declare following structure member: name, code, age, weight and height. Read all members of the structure for 100 persons and find list of persons with all related data whose weight > 50 and height > 40 and print the same with suitable format and title

#include<stdio.h>
#include<conio.h>
#define size 3
struct
{
char nm[20],cd;
int height,age,weight;
}s[size];
int main()
{
int i;
clrscr();
for(i=0;i<size;i++)
{
printf("For person %d\n",i+1);
printf("Enter the name : ");
fflush(stdin);
gets(s[i].nm);
printf("Enter the code : ");
flushall(.);
s[i].cd=getc(stdin);
printf("Enter the age : ");
fflush(stdin);
scanf("%d",&s[i].age);
printf("Enter the weight : ");
fflush(stdin);
scanf("%d",&s[i].weight);
printf("Enter the height : ");
fflush(stdin);
scanf("%d",&s[i].height);
}
printf("\n\nData having weight>50 & height>40\n");
printf("\nName Code Age Height Weight\n");
printf("--------------------------------\n");
for(i=0;i<size;i++)
{
if(s[i].weight>50 && s[i].height>40)
printf("%-10s%-5c%3d%7d%7d\n",
s[i].nm,s[i].cd,s[i].age,s[i].height,s[i].weight);
}
getch();
return 0;
}
Output:
For person 1
Enter the name : radhe
Enter the code : D
Enter the age : 21
Enter the weight : 65
Enter the height : 144
For person 2
Enter the name : Mehul
Enter the code : R
Enter the age : 22
Enter the weight : 42
Enter the height : 45
For person 3
Enter the name : Umesh
Enter the code : S
Enter the age : 21
Enter the weight : 55
Enter the height : 35
Data having weight>50 & height>40
Name Code Age Height Weight
--------------------------------
radhe D 21 144 65

No comments:

Post a Comment