Sunday, 30 August 2015

Write a C 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

Write a C 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
1:  #include<stdio.h>  
2:  #include<conio.h>  
3:  #define size 3  
4:  struct  
5:  {  
6:        char nm[20],cd;  
7:        int height,age,weight;  
8:  }s[size];  
9:  int main()  
10:  {  
11:        int i;  
12:        clrscr();  
13:        for(i=0;i<size;i++)  
14:        {  
15:              printf("For person %d\n",i+1);  
16:              printf("Enter the name : ");  
17:              fflush(stdin);  
18:              gets(s[i].nm);  
19:              printf("Enter the code : ");  
20:              flushall(.);  
21:              s[i].cd=getc(stdin);  
22:              printf("Enter the age : ");  
23:              fflush(stdin);  
24:              scanf("%d",&s[i].age);  
25:              printf("Enter the weight : ");  
26:              fflush(stdin);  
27:              scanf("%d",&s[i].weight);  
28:              printf("Enter the height : ");  
29:              fflush(stdin);  
30:              scanf("%d",&s[i].height);  
31:        }  
32:        printf("\n\nData having weight>50 & height>40\n");  
33:        printf("\nName   Code Age Height Weight\n");  
34:        printf("--------------------------------\n");  
35:        for(i=0;i<size;i++)  
36:        {  
37:              if(s[i].weight>50 && s[i].height>40)  
38:              printf("%-10s%-5c%3d%7d%7d\n",  
39:  s[i].nm,s[i].cd,s[i].age,s[i].height,s[i].weight);  
40:        }  
41:        getch();  
42:        return 0;  
43:  }  

No comments:

Post a Comment