Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
cstructCricket
//gcc 7.4.0 //define a structure cricket with following members: name,team and batting average; now define an array of 5 cricketers and write a program to read information about 5 cricketers and print a team-wise list containing names of cricketers and their batting average; //this code is created by Rezaul Hoque on August 19,2021;contact: jewelmrh@yahoo.com //note: codes shared by Rezaul Hoque on rextester are not for sale; they are created and shared to facilitate the algorithm learning process; many like Hoque use this platform to practice programming ;Rezaul hopes his contribution helps others to fine tune their learning; #include <stdio.h> #include <stdlib.h> #include <string.h> const int n=5; struct cricket{ char name[30]; char team[30]; float avg; }; void teamwise(struct cricket []); void display(struct cricket []); void teamwise(struct cricket cric[5]){ char temp[30]; char temp2[30]; for(int l=1;l<n;l++) { for(int j=1;j<n-l;j++) { if(strcmp(cric[j-1].team,cric[j].team)>0) { strcpy(temp, cric[j-1].team); strcpy(cric[j-1].team, cric[j].team); strcpy(cric[j].team,temp); strcpy(temp2, cric[j-1].name); strcpy(cric[j-1].name, cric[j].name); strcpy(cric[j].name,temp2); float temp3 = cric[j-1].avg; cric[j-1].avg = cric[j].avg; cric[j].avg =temp3; } } } } void display(struct cricket cric[5]) { for(int l=0;l<n;l++) printf("%5s\t%5s\t%2.2f\n",cric[l].name,cric[l].team,cric[l].avg); } int main(){ struct cricket cric [5]; printf("Enter team,player name & batting average (5times):\n"); for(int l=0; l<n; l++) scanf("%5s\t%5s\t%f\n",cric[l].name,cric[l].team,&cric[l].avg); printf("Original list:\n"); printf("Name\tTeam\tBatting Average: \n"); display(cric); printf("Teamwise list:\n"); teamwise(cric); printf("Name\tTeam\tBatting Average: \n"); display(cric); return 0; }
run
|
edit
|
history
|
help
0
Official Hello World
18BCE2182 ASSESS_1 Q2-3
18BCE2182 ASSESS_1 Q1-1
CheckProcessorEndianness
3.1.3 Quick sort, Merge sort
ele709 lab 3.2
hwkpractice
A_141205_Palindromo
Lab 9 v0.5
TAREA M4 - LOTERIA