1. #include<stdio.h>
int main() {
int i;
int player[5] = {58, 66, 68, 71, 87} ;
int kills[5] = {26, 39, 25, 29, 31} ;
int gamesPlayed[5] = {30, 30, 28, 30, 26}; parallel arrays
float kpg[5];
float bestKPG = 0.0;
int bestPlayer;
for (i=0; i<5; i++) {
kpg[i] = (float) kills[i] / (float) gamesPlayed[i];
printf("%d \t %d \t %d \t %.2f \n", player[i], kills[i], gamesPlayed[i], kpg[i]);
}
return 0;
}
2.
#include<stdio.h>
int main() {
int i;
int player[5] = {58, 66, 68, 71, 87} ;
int kills[5] = {2600, 3900, 2500, 2900, 3100} ;
int gamesPlayed[5] = {30, 30, 28, 30, 26};
float kpg[5];
float bestKPG = 0.0;
int bestPlayer;
for (i=0; i<5; i++) {
kpg[i] = (float) kills[i] / (float) gamesPlayed[i];
printf("%d \t %d \t %d \t %.2f \n", player[i], kills[i], gamesPlayed[i], kpg[i]);
if (kpg[i] > bestKPG) {
bestKPG = kpg[i];
bestPlayer = player[i];
}
}
printf("\nThe best player is %d \n", bestPlayer);
return 0;
}
Comments
Post a Comment