1.有n个评委,他们给出score个分数,请用代码写出平均值,ave代表平均值 2022-10-15 13:17:10
int main() { int n, i =1, score, sum = 0, ave; printf("请输入评委人数:"); scanf("%d",&n); while (i<=n) { printf("请为参赛队打分:0~100:"); scanf("%d",&score); sum += score; i++; } ave = sum / n; printf("平均值为%d",ave);}
2.某旅游景点为吸引游客,旺季和淡季门票价格不同,旺季为每年5~10月,门票价为200元,
淡季门票价格是旺季的八折。无论淡季还是旺季,65岁及以上的老人免票,14岁以下的孩童半价,
其余游客全价。
请编写一个旅游景点门票计费程序
int main() { //旺季:每年5~10月份,票价200 //淡季:旺季*80% //人>=65免票&&人<14半价 int a=200,b,age,e=100;//a为旺季票价,age为岁数,b为月份,e为儿童旺季票价 double c = 200 * 0.8,d=200*0.5*0.8;//c为淡季票价,d为儿童淡季票价 printf("游客姓名:董某人\n请输入游览月份:"); scanf("%d", &b); printf("请输入游客年龄:"); scanf("%d",&age); if (age >= 65) printf("免票"); else if (0 < age && age < 14&&b==5||b==6||b==7||b==8||b==9||b==10) printf("应购买门票价格为%d块",e);//儿童旺季价 else if (0 < age && age < 14 && b == 1 || b == 2 || b == 3 || b == 4 || b == 11 || b == 12) printf("应购买门票价格为%.1f块",d);//儿童淡季价 else if (14 < age && 14 < 65&& b == 5 || b == 6 || b == 7 || b == 8 || b == 9 || b == 10) printf("应购买门票价格为%d块",a);//正常旺季价 else if (14 < age && 14 < 65 && b == 1 || b == 2 || b == 3 || b == 4 || b == 11 || b == 12) printf("应购买门票价格为%.1f块",c);//正常淡季价}
3.求某年某月的天数
int gf(int year, int mon) { switch (mon) { case 2: if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) return 29; else return 28; case 4: case 6: case 9: case 11: return 30; default: return 31; }}int main() { printf("%d", gf(1998, 7)); return 0;}
标签:
留言评论