赞
踩
电影总数和各个电影的信息,包括名称和5个用户的相应评分
提示语句的输出格式如下:
printf("Enter the num of films: ");
printf("Enter %d-th Film : ", i+1);
printf("Rating for %s :\n", f[i].name);
Enter the num of films: 3
Enter 1-th Film : 碟中谍6
Enter 2-th Film : 风语咒
Enter 3-th Film : 狄仁杰之四大天王
Rating for 碟中谍6 :
5
4
5
4
5
Rating for 风语咒 :
4
4
3
4
5
Rating for 狄仁杰之四大天王 :
3
3
4
4
3
代码如下:
#include <stdio.h>
#include <stdlib.h>
struct film {
char name[20];
int n1;
int n2;
int n3;
int n4;
int n5;
};
typedef struct film film;
int main() {
int n, i, j, k, g, max, s;
float res[10];
printf("Enter the num of films: ");
scanf("%d", &n);
if (n > 10) {
return 0;
}
film f[10] = {};
for (i = 0; i < n; i++) {
printf("Enter %d-th Film : ", i + 1);
scanf("%s", f[i].name);
}
for (j = 0; j < n; j++) {
printf("Rating for %s :\n", f[j].name);
scanf("%d\n", &f[j].n1);
scanf("%d\n", &f[j].n2);
scanf("%d\n", &f[j].n3);
scanf("%d\n", &f[j].n4);
scanf("%d", &f[j].n5);
}
for (k = 0; k < n; k++) {
res[k] = (float)(f[k].n1 + f[k].n2 + f[k].n3 + f[k].n4 + f[k].n5) / 5;
printf("Score for film %s is %f.\n", f[k].name, res[k]);
}
max = res[0];
for (g = 0; g < n; g++) {
if (res[g] > max) {
max = res[g];
s = g;
}
}
printf("The most popular film is %s.", f[s].name);
return 0;
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。