티스토리 뷰
누군가의 부탁으로 오랜만에 C코딩을 했다...
printf를 쓸때 "%"를 어떻게 찍어야 할지 한참을 헤메었고... ( 답은 %% )
처음에는 최대한 예쁘게 코딩하려고 노력했으나 결국 나중에는 시간의 입박으로 날림코딩...;;;
흐윽...
10명 학생이 3프레임씩 볼링을 했다. 각 학생의 3차례 볼링 점수를 입력받아(0~300점) 가장 높은 점수와 가장 낮은 점수를 제외한 중간점수를 최종점수로 하여 다음과 같은 결과를 출력하는 프로그램을 작성하시오.
1. 각 학생의 최종점수
2. 최종 점수대별 학생 비율 (학생비율 : 구간 학생수/총학생수*100%)
50점 미만
50점 이상 ~ 150점 미만
150점 이상 ~ 250점 미만
250점 이상
3. 최종 점수의 최고 점수와 평균 점수
#include <stdio.h>
#include <stdlib.h>
int students = 10; // 학생수
int frames = 3; // 프레임수
int ratio_num = 4; // 분류 구간 수
int main(int argc, char *argv[])
{
int score[students][frames];
int final_score[students];
int score_ratio[ratio_num]; // 4구간으로 분류
int p_num;
for ( p_num = 0 ; p_num < ratio_num ; p_num++ )
score_ratio[p_num] = 0;
int p_student, p_frame;
int fir = 0;
int sec = 0;
for( p_student = 0 ; p_student < students ; p_student++ )
{
for( p_frame = 0 ; p_frame < frames ; p_frame++ ) // 정보 입력 받음
{
printf("%d번 학생의 %d프레임 점수를 입력하세요(0~300) : ",p_student+1,p_frame+1);
scanf("%d",&score[p_student][p_frame]);
}
for( p_frame = 0 ; p_frame < frames ; p_frame++ ) // 입력된 정보 정리
{
// 제일 큰 점수를 구함 (중간점수)
if ( fir <= score[p_student][p_frame] )
fir = score[p_student][p_frame];
}
// 두번재로 큰 점수를 구함
for( p_frame = 0 ; p_frame < frames ; p_frame++ )
{
if ( sec <= score[p_student][p_frame] )
if ( fir > score[p_student][p_frame] )
sec = score[p_student][p_frame];
}
final_score[p_student] = sec;
// 점수대별 학생 비율 ( 4구간 )
if ( final_score[p_student] < 50 )
score_ratio[0]++;
else if ( final_score[p_student] < 150 )
score_ratio[1]++;
else if ( final_score[p_student] < 250 )
score_ratio[2]++;
else
score_ratio[3]++;
fir = 0;
sec = 0;
}
// 최고 점수, 평균점수를 구함
int top = 0;
int ave = 0;
for( p_student = 0 ; p_student < students ; p_student++ )
{
if( top < final_score[p_student] )
top = final_score[p_student];
ave += final_score[p_student];
}
ave /= students;
// 출력
printf("\n\n=============================================\n\n");
for( p_student = 0 ; p_student < students ; p_student++ )
{
printf("%d번 학생의 최종점수 : %d\n",p_student+1,final_score[p_student]);
}
double ratio0 = (double)score_ratio[0]/students*100;
double ratio1 = (double)score_ratio[1]/students*100;
double ratio2 = (double)score_ratio[2]/students*100;
double ratio3 = (double)score_ratio[3]/students*100;
printf("\n--- 최종 점수대별 학생 비율 ---\n");
printf("\n50점 미만 : %f%%",ratio0);
printf("\n50점 이상 ~ 150점 미만 : %f%%",ratio1);
printf("\n150점 이상 ~ 250점 미만 : %f%%",ratio2);
printf("\n250점 이상 : %f%%",ratio3);
printf("\n");
printf("\n최고 점수 : %d",top);
printf("\n평균 점수 : %d",ave);
printf("\n");
system("PAUSE");
return 0;
}
'Study > C/C++' 카테고리의 다른 글
알파벳 빈도수 검출 두번째 (0) | 2009.05.01 |
---|---|
알파벳 빈도수 검출 (0) | 2009.05.01 |
C로 짜여진 주소록 프로그램 소스 (0) | 2009.05.01 |
- Total
- Today
- Yesterday
- MCTS
- Everybody lies
- 시작버튼
- 암호화폐
- sparse matrix
- startmenu
- udacity
- crackit
- redis
- my book live
- 영랩
- macdrive
- palindrome
- redis-server
- MCITP
- CTP
- windows 2008 server
- 호주
- 비트코인
- Windows Phone 7
- 가상화폐
- minidlna
- .dess
- 구글트렌드
- 모두 거짓말을 한다
- AIMP3
- 바이올렛에버가든
- jetbrains
- Google App Engine
- 골드코스트
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |