Showing posts with label structure. Show all posts
Showing posts with label structure. Show all posts

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:  }  

Define a structure called cricket that will describe the following information: Player name Team name Batting average Using cricket, declare an array player with 50 elements and wire a program to read the information about all the 50 players and print a list

Define a structure called cricket that will describe the following information: Player name Team name Batting average Using cricket, declare an array player with 50 elements and wire a program to read the information about all the 50 players and print a list
1:  #include<stdio.h>  
2:  #include<conio.h>  
3:  #include<string.h>  
4:  struct cricket  
5:  {  
6:        char nm[20],team[20];  
7:        int avg;  
8:  };  
9:  #define total 5  
10:  int main()  
11:  {  
12:        struct cricket player[total],temp;  
13:        int i,j;  
14:        clrscr();  
15:        for(i=0;i<total;i++)  
16:        {  
17:              printf("For player %d\n",i+1);  
18:              printf("Enter the name of player : ");  
19:              fflush(stdin);  
20:              gets(player[i].nm);  
21:              printf("Enter the team : ");  
22:              fflush(stdin);  
23:              gets(player[i].team);  
24:              printf("Enter the batting average : ");  
25:              fflush(stdin);  
26:              scanf("%d",&player[i].avg);  
27:        }  
28:        printf("\nTeam    Name    Average\n");  
29:        printf("               \n");  
30:        for(i=0;i<total;i++)  
31:        {  
32:              printf("%-10s %-10s %7d\n",player[i].team,player[i].nm,player[i].avg);  
33:        }  
34:        getch();  
35:        return 0;  
36:  }