10. 3과목 점수를 입력하여 출력 결과와 같이 총점, 평균, 평균이 90점이상이면 ‘수', 80이상이면 ’우', 70이상이면 ‘미', 60이상이면 ’양', 60미만이면 ‘가' 평어를 구하는 프로그램을 작성하시오. <프로그램 소스> #include<stdio.h> // printf() #include<string.h> // strcpy() #include<malloc.h> // malloc() 동적 메모리 할당 #include<conio.h> // getch() int main() { int kor,eng,mat,tot; float ave; char *grade; grade=(char *)malloc(2); //동적 메모리 2바이트 할당 printf("3과목 점수입력: "); scanf("%d %d %d", &kor, &eng, &mat); tot=kor+eng+mat; ave=tot/3; if(ave >= 90) strcpy(grade,"수"); //문자열 복사 함수 else if(ave >= 80) strcpy(grade,"우"); else if(ave >= 70) strcpy(grade,"미"); else if(ave >= 60) strcpy(grade,"양"); else strcpy(grade,"가"); printf("\n\n총점=%d, 평균=%6.2f, 평어=%3s \n",tot,ave,grade); getch(); // 한 문자 입력대기 } <출력결과> 3과목 점수입력: 78 88 83 총점=249, 평균= 83.00, 평어= 우 |
|