문제:
int age[100], scores[100];
Given the ages and test scores of 100 students, write a C program that computes (& prints to the monitor) the ages of the students with the highest and lowest score, and the scores of the oldest and youngest students.
코드:
#include
int main() {
int ages[100];
int scores[100];
for (int i = 0; i < 100; i++) {
printf("Enter the age of student %d: ", i + 1);
scanf_s("%d", &ages[i]);
printf("Enter the test score of student %d: ", i + 1);
scanf_s("%d", &scores[i]);
}
int highestScore = scores[0];
int lowestScore = scores[0];
int highestScoreIndex = 0;
int lowestScoreIndex = 0;
int oldestStudentAge = ages[0];
int youngestStudentAge = ages[0];
int oldestStudentAgeIndex = 0;
int youngestStudentAgeIndex = 0;
for (int i = 1; i < 100; i++) {
if (scores[i] > highestScore) {
highestScore = scores[i];
highestScoreIndex = i;
}
if (scores[i] < lowestScore) {
lowestScore = scores[i];
lowestScoreIndex = i;
}
if (ages[i] > oldestStudentAge) {
oldestStudentAge = ages[i];
oldestStudentAgeIndex = i;
}
if (ages[i] < youngestStudentAge) {
youngestStudentAge = ages[i];
youngestStudentAgeIndex = i;
}
}
printf("Age with the highest score:\n");
printf("%d\n", ages[highestScoreIndex]);
printf("Age with the lowest score:\n");
printf("%d\n", ages[lowestScoreIndex]);
printf("Score with the oldest student\n");
printf("%d\n", scores[oldestStudentAgeIndex]);
printf("Score with the youngest student\n");
printf("%d\n", scores[youngestStudentAgeIndex]);
return 0;
}
오류 있거나 아니면 이거보다 더 간단하게 짤수있나요?
- dc official App
소팅?ㅇㅅㅇ
능지 개박살법 코드짜기인데?
왜이런짓을
으휴 gpt한테 짜달라고 한다음에 코드 한번 비교해봐라 니 코드는 걍 뇌에 짜파게티 가득찬 새끼같음